build static method
Future<SecureHydratedStorage>
build(
- dynamic secureStorage, {
- String prefix = kDefaultHydratedStoragePrefix,
Asynchronously pre-loads stored keys matching prefix from
secureStorage into memory, returning a fully initialized
SecureHydratedStorage ready for synchronous frame 1 state hydration.
Defaults prefix to kDefaultHydratedStoragePrefix so foreign keychain
entries are ignored. Pass prefix: '' explicitly if you must read legacy
unprefixed keys.
Implementation
static Future<SecureHydratedStorage> build(
dynamic secureStorage, {
String prefix = kDefaultHydratedStoragePrefix,
}) async {
// Duck-typing support for flutter_secure_storage FlutterSecureStorage.
// ignore: avoid_dynamic_calls
final dynamic rawAll = await secureStorage.readAll();
final all = Map<String, String>.from(
(rawAll as Map).map((k, v) => MapEntry(k.toString(), v.toString())),
);
final cache = <String, dynamic>{};
for (final entry in all.entries) {
if (prefix.isEmpty || entry.key.startsWith(prefix)) {
final rawKey = prefix.isNotEmpty && entry.key.startsWith(prefix)
? entry.key.substring(prefix.length)
: entry.key;
try {
cache[rawKey] = jsonDecode(entry.value);
} on FormatException {
cache[rawKey] = entry.value;
}
}
}
return SecureHydratedStorage._(secureStorage, cache, prefix: prefix);
}