Skip to content

Commit

Permalink
fix: remote config bug with saving the remote config in memory
Browse files Browse the repository at this point in the history
  • Loading branch information
vanlooverenkoen committed Apr 22, 2024
1 parent 8b60561 commit 8c0401a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 0.1.1

## Fix

- RemoteConfigRepository bug with setting the actual remote config

# 0.1.0

## Feat
Expand Down
15 changes: 12 additions & 3 deletions lib/src/repo/remote_config/remote_config_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,28 @@ abstract class RemoteConfigRepository<T extends ImpaktfullRemoteConfigData> {
final json = jsonEncode(toJson(remoteConfigData));
ImpaktfullLogger.debug('REMOTE_CONFIG: Saving remote config data: $json');
await _sharedPrefsStore.saveString(key: storageKey, value: json);
ImpaktfullRemoteConfigData.configure(remoteConfigData);
return remoteConfigData;
} catch (e) {
ImpaktfullLogger.debug(
'REMOTE_CONFIG: Failed to fetch data from remote config, try cache');
try {
final json = await _sharedPrefsStore.getString(key: storageKey);
if (json == null) return getDefault();
if (json == null) {
final remoteConfigData = await getDefault();
ImpaktfullRemoteConfigData.configure(remoteConfigData);
return remoteConfigData;
}
final jsonData = jsonDecode(json) as Map<String, dynamic>;
return fromJson(jsonData);
final remoteConfigData = fromJson(jsonData);
ImpaktfullRemoteConfigData.configure(remoteConfigData);
return remoteConfigData;
} catch (e) {
ImpaktfullLogger.debug(
'REMOTE_CONFIG: Failed to fetch data from cache, use default');
return getDefault();
final remoteConfigData = await getDefault();
ImpaktfullRemoteConfigData.configure(remoteConfigData);
return remoteConfigData;
}
}
}
Expand Down

0 comments on commit 8c0401a

Please sign in to comment.