requestValue method

Future<void> requestValue(
  1. String key,
  2. bool legacy
)

Requests the value for a given key and posts an event with the result.

Implementation

Future<void> requestValue(String key, bool legacy) async {
  final Object? value;
  if (legacy) {
    final EncryptedSharedPreferences legacyPrefs =
        EncryptedSharedPreferences.getInstance();
    value = legacyPrefs.get(key);
  } else {
    final EncryptedSharedPreferencesAsync preferences =
        EncryptedSharedPreferencesAsync.getInstance();
    value = await EncryptedSharedPreferencesAsync.getInstance()
        .getAsMap(allowList: <String>{key}).then(
            (Map<String, Object?> map) => map.values.firstOrNull);
  }

  _postEvent('${_eventPrefix}value', <String, Object?>{
    'value': value,
    // It is safe to use `runtimeType` here. This code
    // will only ever run in debug mode.
    'kind': value.runtimeType.toString(),
  });
}