load method

Future<void> load()

Implementation

Future<void> load() async {
  try {
    final encrypted = await storage.load(storageKey);
    if (encrypted == null) return;

    final decryptionKey = encryptionKey ?? _getDefaultKey();
    final decrypted = await encryption.decrypt(encrypted, key: decryptionKey);
    final data = jsonDecode(decrypted) as Map<String, dynamic>;

    _value = data['value'] as T;
  } catch (e) {
    debugPrint('Error loading encrypted data: $e');
    // Don't rethrow - use initial value
  }
}