read<T> method

Future<T?> read<T>(
  1. String key
)

Implementation

Future<T?> read<T>(String key) async {
  try {
    final prefixedKey = '${StorageConfig.securePrefix}$key';
    final String? value = await _storage.read(key: prefixedKey);

    if (value == null) return null;

    try {
      final decoded = jsonDecode(value);

      final currentData = Map<String, dynamic>.from(_dataSubject.value);
      currentData[key] = decoded;
      _dataSubject.add(currentData);

      return decoded as T;
    } catch (_) {
      return value as T;
    }
  } catch (e) {
    debugPrint('IceStorage SecureService: Error leyendo $key - $e');
    return null;
  }
}