Skip to content

Commit

Permalink
feat: add loadSilently to avoid triggering loading state
Browse files Browse the repository at this point in the history
  • Loading branch information
adar2378 committed Oct 17, 2023
1 parent c9de71e commit 86ebd16
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
Expand Up @@ -44,10 +44,13 @@ abstract class RemoteConfigCubit extends HydratedCubit<RemoteConfigState>
/// [lastUpdate] is the timestamp provided by app_launch part to know when was the last time
/// config was updated. if [lastUpdate] is older then we should call [load] to get latest data
/// otherwise can be used via hydrated state.
Future<void> load({DateTime? lastUpdate}) async {
Future<void> load({DateTime? lastUpdate, bool? loadSilently}) async {
await _remoteConfigApiChecker(() async {
try {
emit(state.copyWith(isLoading: true));
if (loadSilently != true) {
emit(state.copyWith(isLoading: true));
}

final result = (await remoteconfigApi!.remoteconfigRetrieve(
part_: part,
params: params,
Expand Down
Expand Up @@ -9,10 +9,12 @@ class RemoteConfigPartUpdater<C extends RemoteConfigCubit>
super.key,
required this.create,
this.child,
this.loadSilently,
});

final C Function(BuildContext context) create;
final Widget? child;
final bool? loadSilently;

@override
State<RemoteConfigPartUpdater<C>> createState() =>
Expand Down Expand Up @@ -77,12 +79,17 @@ class _RemoteConfigPartUpdaterState<C extends RemoteConfigCubit>
if (remoteLastUpdateTimeStamp != null) {
if (localLastUpdateTimeStamp == null ||
remoteLastUpdateTimeStamp.isAfter(localLastUpdateTimeStamp)) {
cubit.load(lastUpdate: remoteLastUpdateTimeStamp);
cubit.load(
lastUpdate: remoteLastUpdateTimeStamp,
loadSilently: widget.loadSilently,
);
}
}
} else {
// fetch data fallback
cubit.load();
cubit.load(
loadSilently: widget.loadSilently,
);
}
}
}

0 comments on commit 86ebd16

Please sign in to comment.