onTransition method Null safety

  1. @protected
  2. @mustCallSuper
void onTransition(
  1. Transition<Event, State> transition

Called whenever a transition occurs with the given transition. A transition occurs when a new event is added and mapEventToState executed. onTransition is called before a Bloc's state has been updated. A great spot to add logging/analytics at the individual Bloc level.

Note: super.onTransition should always be called first.

void onTransition(Transition<Event, State> transition) {
  // Always call super.onTransition with the current transition

  // Custom onTransition logic goes here

See also:


void onTransition(Transition<Event, State> transition) {
  // ignore: invalid_use_of_protected_member
  Bloc.observer.onTransition(this, transition);