Last active
April 1, 2025 15:19
-
-
Save alexmercerind/56b0be81e6cbc78646b2e3b2d5d10ab4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Future<O> _read<I, O>(String key, Map<String, dynamic> defaults, [O Function(I)? map]) async { | |
if (I == O) { | |
map ??= (value) => value as O; | |
} else if (map == null) { | |
throw ArgumentError(); | |
} | |
try { | |
return switch (I) { | |
const (bool) => map(await db.getBoolean(key) as I), | |
const (int) => map(await db.getInteger(key) as I), | |
const (double) => map(await db.getDouble(key) as I), | |
const (String) => map(await db.getString(key) as I), | |
_ => map(await db.getJson(key) as I), | |
}; | |
} catch (exception, stacktrace) { | |
debugPrint(exception.toString()); | |
debugPrint(stacktrace.toString()); | |
return defaults[key]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment