clearState method

Future<void> clearState(
  1. String type
)

Clears the shared state for a specific type.

This method:

  1. Ensures state is synced
  2. Sets the cached state to null
  3. Notifies local listeners
  4. 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}');
  }
}