2023-07-17 09:35:45 +02:00
|
|
|
import 'package:nc_photos/entity/pref.dart';
|
|
|
|
import 'package:nc_photos/use_case/compat/v34.dart';
|
2023-08-28 19:22:29 +02:00
|
|
|
import 'package:np_universal_storage/np_universal_storage.dart';
|
2023-07-17 09:35:45 +02:00
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
|
|
|
|
/// [Pref] stored with [SharedPreferences] lib
|
|
|
|
class PrefSharedPreferencesProvider extends PrefProvider {
|
|
|
|
Future<void> init() async {
|
|
|
|
// Obsolete, CompatV34 is compatible with pre v32 versions
|
|
|
|
// if (await CompatV32.isPrefNeedMigration()) {
|
|
|
|
// await CompatV32.migratePref();
|
|
|
|
// }
|
|
|
|
if (await CompatV34.isPrefNeedMigration()) {
|
2023-08-28 19:22:29 +02:00
|
|
|
await CompatV34.migratePref(UniversalStorage());
|
2023-07-17 09:35:45 +02:00
|
|
|
}
|
|
|
|
return SharedPreferences.getInstance().then((pref) {
|
|
|
|
_pref = pref;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
2023-07-17 10:23:57 +02:00
|
|
|
bool? getBool(PrefKeyInterface key) => _pref.getBool(key.toStringKey());
|
2023-07-17 09:35:45 +02:00
|
|
|
|
|
|
|
@override
|
2023-07-17 10:23:57 +02:00
|
|
|
Future<bool> setBool(PrefKeyInterface key, bool value) =>
|
2023-07-17 09:35:45 +02:00
|
|
|
_pref.setBool(key.toStringKey(), value);
|
|
|
|
|
|
|
|
@override
|
2023-07-17 10:23:57 +02:00
|
|
|
int? getInt(PrefKeyInterface key) => _pref.getInt(key.toStringKey());
|
2023-07-17 09:35:45 +02:00
|
|
|
|
|
|
|
@override
|
2023-07-17 10:23:57 +02:00
|
|
|
Future<bool> setInt(PrefKeyInterface key, int value) =>
|
2023-07-17 09:35:45 +02:00
|
|
|
_pref.setInt(key.toStringKey(), value);
|
|
|
|
|
|
|
|
@override
|
2023-07-17 10:23:57 +02:00
|
|
|
String? getString(PrefKeyInterface key) => _pref.getString(key.toStringKey());
|
2023-07-17 09:35:45 +02:00
|
|
|
|
|
|
|
@override
|
2023-07-17 10:23:57 +02:00
|
|
|
Future<bool> setString(PrefKeyInterface key, String value) =>
|
2023-07-17 09:35:45 +02:00
|
|
|
_pref.setString(key.toStringKey(), value);
|
|
|
|
|
|
|
|
@override
|
2023-07-17 10:23:57 +02:00
|
|
|
List<String>? getStringList(PrefKeyInterface key) =>
|
2023-07-17 09:35:45 +02:00
|
|
|
_pref.getStringList(key.toStringKey());
|
|
|
|
|
|
|
|
@override
|
2023-07-17 10:23:57 +02:00
|
|
|
Future<bool> setStringList(PrefKeyInterface key, List<String> value) =>
|
2023-07-17 09:35:45 +02:00
|
|
|
_pref.setStringList(key.toStringKey(), value);
|
|
|
|
|
|
|
|
@override
|
2023-07-17 10:23:57 +02:00
|
|
|
Future<bool> remove(PrefKeyInterface key) => _pref.remove(key.toStringKey());
|
2023-07-17 09:35:45 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
Future<bool> clear() => _pref.clear();
|
|
|
|
|
|
|
|
late SharedPreferences _pref;
|
|
|
|
}
|