Skip to content

Commit

Permalink
feat(neon_framework): add a storage version to the SharedPreferencesP…
Browse files Browse the repository at this point in the history
…ersistence

Signed-off-by: Nikolas Rimikis <leptopoda@users.noreply.github.com>
  • Loading branch information
Leptopoda committed Feb 25, 2024
1 parent 844e490 commit 786c29c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ final class SharedPreferencesPersistence implements CachedPersistence {
final fromSystem = await _store.getAll();
_globalCache.addAll(fromSystem);

const versionKey = 'neon-version';
const persistence = SharedPreferencesPersistence();
if (!persistence.containsKey(versionKey)) {
await persistence.setValue(versionKey, kSharedPreferenceVersion);
}

_initialized = true;
}

Expand Down
7 changes: 6 additions & 1 deletion packages/neon_framework/test/persistence_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ void main() {
expect(
stored,
equals({
'flutter.neon-version': kSharedPreferenceVersion,
'flutter.no_prefix': 56,
'flutter.another-prefix': true,
}),
Expand Down Expand Up @@ -137,7 +138,11 @@ void main() {

await persistence.clear();
stored = await sharedPreferences.getAll();
expect(stored, isEmpty);
expect(
stored,
isEmpty,
reason: 'An empty prefix matches every non empty one. Clearing everything.',
);

await sharedPreferences.setValue('valueType', 'flutter.key', 'value');
await persistence.reload();
Expand Down

0 comments on commit 786c29c

Please sign in to comment.