Add Config options import

This commit is contained in:
problematicconsumer
2024-03-04 15:58:56 +03:30
parent 9c2e9d8d85
commit d87e207771
13 changed files with 216 additions and 63 deletions

View File

@@ -71,6 +71,17 @@ class PreferencesEntry<T, P> with InfraLogger {
}
}
Future<T?> writeRaw(P input) async {
final T value;
if (mapFrom != null) {
value = mapFrom!(input);
} else {
value = input as T;
}
if (await write(value)) return value;
return null;
}
Future<void> remove() async {
try {
await preferences.remove(key);
@@ -145,6 +156,11 @@ class PreferencesNotifier<T, P> extends StateNotifier<T> {
return value as P;
}
Future<void> updateRaw(P input) async {
final value = await entry.writeRaw(input);
if (value != null) state = value;
}
Future<void> update(T value) async {
if (await entry.write(value)) state = value;
}