setState method

  1. @protected
void setState(
  1. T update, {
  2. String? event,
})
inherited

Called by blocs (subclasses) when the state is updated

isBusy and error are cleared whenever the state is updated Optional argument event is the name of event which is calling setState

Implementation

@protected
void setState(S update, {String? event}) {
  if (!_kReleaseMode) {
    event ??= _caller;
  }

  final stream = this._stream;
  _monitor.onEvent(this, _state, update, event: event);
  final next = nextState(_state, update);
  _isBusy = false;
  _error = null;

  if (next == null) {
    return;
  }

  _state = next;
  if (stream != null) {
    stream.add(_state);
    notifyListeners(BlocEventType.stateChange);
    _monitor.onBroadcast(this, _state, event: event);
  }
}