build static method

Future<SecureHydratedStorage> build(
  1. dynamic secureStorage, {
  2. String prefix = '',
})

Asynchronously pre-loads stored keys from secureStorage into memory, returning a fully initialized SecureHydratedStorage ready for synchronous frame 1 state hydration.

Implementation

static Future<SecureHydratedStorage> build(
  dynamic secureStorage, {
  String prefix = '',
}) 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 Object {
        cache[rawKey] = entry.value;
      }
    }
  }
  return SecureHydratedStorage._(secureStorage, cache, prefix: prefix);
}