emit method

void emit(
  1. State state
)

Updates the state to the provided state. emit does nothing if the instance has been closed or if the state being emitted is equal to the current state.

To allow for the possibility of notifying listeners of the initial state, emitting a state which is equal to the initial state is allowed as long as it is the first thing emitted by the instance.

Implementation

void emit(State state) {
  if (_stateController.isClosed) return;
  if (state == this.state && _emitted) return;
  onChange(StateChange<State>(currentState: this.state, nextState: state));
  _state = state;
  _stateController.add(state);
  _emitted = true;
}