write method

Future<void> write(
  1. String key,
  2. dynamic value
)

Implementation

Future<void> write(String key, dynamic value) async {
  try {
    final prefixedKey = '${StorageConfig.securePrefix}$key';

    // Codificacion con manejo de Timestamps
    final String encodedValue = value is String
        ? value
        : jsonEncode(value, toEncodable: customJsonEncoder);

    await _storage.write(key: prefixedKey, value: encodedValue);

    final currentData = Map<String, dynamic>.from(_dataSubject.value);
    currentData[key] = value;
    _dataSubject.add(currentData);
  } catch (e) {
    throw StorageException(
      'Error escribiendo dato seguro',
      details: e.toString(),
      type: StorageType.secure,
    );
  }
}