chore: Follow up migrate old preferences

This commit is contained in:
Christian Pauly 2022-02-17 09:43:31 +01:00
commit 33d608b836
4 changed files with 146 additions and 0 deletions

View file

@ -1,7 +1,10 @@
import 'dart:core';
import 'package:matrix/matrix.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'legacy_famedlysdk_store.dart' as legacy;
class Store {
SharedPreferences? _prefs;
@ -11,11 +14,25 @@ class Store {
Future<String?> getItem(String key) async {
await _setupLocalStorage();
final legacyVal = await legacy.Store().getItem(key);
if (legacyVal != null) {
Logs().d('Found legacy preference for $key');
await setItem(key, legacyVal);
legacy.Store().deleteItem(key);
return legacyVal;
}
return _prefs!.getString(key);
}
Future<bool> getItemBool(String key, [bool? defaultValue]) async {
await _setupLocalStorage();
final legacyVal = await legacy.Store().getItemBool(key);
if (legacyVal != null) {
Logs().d('Found legacy preference for $key');
await setItemBool(key, legacyVal);
legacy.Store().deleteItem(key);
return legacyVal;
}
return _prefs!.getBool(key) ?? defaultValue ?? true;
}