getValue method

Future<String?> getValue(
  1. String key
)

Retrieves a value from the cache or SecureStorage

Implementation

Future<String?> getValue(String key) async {
  // Check if value is already in the cache
  if (_cache.containsKey(key) && _cache[key] != null) {
    return _cache[key];
  }

  // If not in cache, fetch it from SecureStorage
  try {
    final value = await SecureStorage.getSecureData(key);
    if (value != null) {
      _cache[key] = value;
      return value;
    }
    return null;
  } catch (error) {
    // ignore: avoid_print
    print('Error fetching key $key from SecureStorage: $error');
    return null;
  }
}