sync method

void sync(
  1. T? state
)

Updates the shared state and notifies all displays.

This method:

  1. Updates the local state
  2. Notifies local listeners via notifyListeners
  3. Propagates the change to all other Flutter engines

If the new state equals the current state, no update occurs.

@param state The new state value, or null to clear

Implementation

void sync(T? state) {
  if (_state == state) return; // Avoid unnecessary updates
  _state = state;
  debugPrint('[SharedState] Syncing state for $_type: $state');
  notifyListeners();
  SharedStateManager.instance.updateState(_type, toJson(state));
}