import 'package:nc_photos/entity/pref.dart'; import 'package:nc_photos/use_case/compat/v34.dart'; import 'package:np_universal_storage/np_universal_storage.dart'; import 'package:shared_preferences/shared_preferences.dart'; /// [Pref] stored with [SharedPreferences] lib class PrefSharedPreferencesProvider extends PrefProvider { Future init() async { // Obsolete, CompatV34 is compatible with pre v32 versions // if (await CompatV32.isPrefNeedMigration()) { // await CompatV32.migratePref(); // } if (await CompatV34.isPrefNeedMigration()) { await CompatV34.migratePref(UniversalStorage()); } return SharedPreferences.getInstance().then((pref) { _pref = pref; }); } @override bool? getBool(PrefKeyInterface key) => _pref.getBool(key.toStringKey()); @override Future setBool(PrefKeyInterface key, bool value) => _pref.setBool(key.toStringKey(), value); @override int? getInt(PrefKeyInterface key) => _pref.getInt(key.toStringKey()); @override Future setInt(PrefKeyInterface key, int value) => _pref.setInt(key.toStringKey(), value); @override String? getString(PrefKeyInterface key) => _pref.getString(key.toStringKey()); @override Future setString(PrefKeyInterface key, String value) => _pref.setString(key.toStringKey(), value); @override List? getStringList(PrefKeyInterface key) => _pref.getStringList(key.toStringKey()); @override Future setStringList(PrefKeyInterface key, List value) => _pref.setStringList(key.toStringKey(), value); @override Future remove(PrefKeyInterface key) => _pref.remove(key.toStringKey()); @override Future clear() => _pref.clear(); late SharedPreferences _pref; }