storeInternalState method
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;
}
}