Fix general issues

This commit is contained in:
problematicconsumer
2023-09-06 21:03:43 +03:30
parent 42ea79c7e5
commit b03d8cba99
10 changed files with 40 additions and 42 deletions

View File

@@ -95,26 +95,32 @@ mixin _Prefs<T> implements LoggerMixin {
/// Updates the value asynchronously.
Future<void> update(T value) async {
if (mapTo != null && mapFrom != null) {
await prefs.setString(key, mapTo!(value));
} else {
switch (value) {
case String _:
await prefs.setString(key, value);
case bool _:
await prefs.setBool(key, value);
case int _:
await prefs.setInt(key, value);
case double _:
await prefs.setDouble(key, value);
case List<String> _:
await prefs.setStringList(key, value);
loggy.debug("updating preference [$key] to [$value]");
try {
if (mapTo != null && mapFrom != null) {
await prefs.setString(key, mapTo!(value));
} else {
switch (value) {
case String _:
await prefs.setString(key, value);
case bool _:
await prefs.setBool(key, value);
case int _:
await prefs.setInt(key, value);
case double _:
await prefs.setDouble(key, value);
case List<String> _:
await prefs.setStringList(key, value);
}
}
} catch (e) {
loggy.warning("error updating preference[$key]: $e");
}
}
T getValue() {
try {
loggy.debug("getting persisted preference [$key]");
if (mapTo != null && mapFrom != null) {
final persisted = prefs.getString(key);
return persisted != null ? mapFrom!(persisted) : defaultValue;