clearState method
Clears the shared state for a specific type.
This method:
- Ensures state is synced
- Sets the cached state to null
- Notifies local listeners
- Sends the clear command to the native side
@param type The state type identifier to clear
Implementation
Future<void> clearState(String type) async {
try {
if (!_hasSyncData) {
await _syncSharedState();
}
if (_cachedSharedState[type] != null) {
_cachedSharedState[type] = null;
debugPrint('[SharedStateManager] Clearing state for $type');
_notifyListeners(type, null);
await methodChannel.invokeMethod('clearState', {'type': type});
}
} on PlatformException catch (e) {
debugPrint('Error clearing shared state: ${e.message}');
}
}