storeInternalState method

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

Almacena estado interno

Implementation

Future<void> storeInternalState(String key, dynamic value) async {
  ObslyLogger.verbose('πŸ”΅ ObslyStorage.storeInternalState() called - key: $key, initialized: $_isInitialized');

  if (!_isInitialized) {
    ObslyLogger.verbose('πŸ”΅ Storage not initialized, calling initialize()...');
    await initialize();
  }

  try {
    ObslyLogger.verbose(
        'πŸ”΅ Storage state: useHive=$_useHive, internalStateBox=${_internalStateBox != null}, prefs=${_prefs != null}');

    if (_useHive && _internalStateBox != null) {
      ObslyLogger.verbose('πŸ”΅ Storing in Hive box...');
      await _internalStateBox!.put(key, value);
      ObslyLogger.verbose('βœ… Successfully stored in Hive: $key');
    } else if (_prefs != null) {
      ObslyLogger.verbose('πŸ”΅ Storing in SharedPreferences...');
      if (value is String) {
        await _prefs!.setString('obsly_state_$key', value);
      } else if (value is int) {
        await _prefs!.setInt('obsly_state_$key', value);
      } else if (value is bool) {
        await _prefs!.setBool('obsly_state_$key', value);
      } else {
        await _prefs!.setString('obsly_state_$key', jsonEncode(value));
      }
      ObslyLogger.log('βœ… Successfully stored in SharedPreferences: $key');
    } else {
      ObslyLogger.error('❌ No storage backend available! Hive failed and SharedPreferences not available');
      throw Exception('No storage backend available');
    }
  } catch (e) {
    ObslyLogger.error('❌ Error storing internal state for key "$key": $e');
    rethrow;
  }
}