initialize method

Future<void> initialize()

Implementation

Future<void> initialize() async {
  try {
    final allData = await _storage.readAll();
    final Map<String, dynamic> processedData = {};

    for (var entry in allData.entries) {
      if (entry.key.startsWith(StorageConfig.securePrefix)) {
        final cleanKey = entry.key.replaceFirst(StorageConfig.securePrefix, '');
        try {
          processedData[cleanKey] = jsonDecode(entry.value);
        } catch (_) {
          processedData[cleanKey] = entry.value;
        }
      }
    }

    _dataSubject.add(processedData);
  } on PlatformException catch (e) {
    if (CryptoErrorHandler.isCryptoError(e)) {
      await CryptoErrorHandler.resetCorruptedStore(_storage);
      _dataSubject.add({});
      return;
    }

    throw StorageException(
      'Error inicializando SecureService',
      details: e.toString(),
      type: StorageType.secure,
    );
  } catch (e) {
    throw StorageException(
      'Error inicializando SecureService',
      details: e.toString(),
      type: StorageType.secure,
    );
  }
}