onTransition method

  1. @override
void onTransition(
  1. Transition<LyFormEvent, LyFormState<D, E>> transition
)

Called whenever a transition occurs with the given transition. A transition occurs when a new event is added and a new state is emitted from a corresponding EventHandler.

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.

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

  // Custom onTransition logic goes here
}

See also:

  • BlocObserver.onTransition for observing transitions globally.

Implementation

@override
void onTransition(Transition<LyFormEvent, LyFormState<D, E>> transition) {
  super.onTransition(transition);
  final state = transition.nextState;
  if (state is LyFormPureState<D, E>) {
    onPureState(state);
  } else if (state is LyFormInvalidState<D, E>) {
    onInvalidState(state);
  } else if (state is LyFormValidState<D, E>) {
    onValidState(state);
  } else if (state is LyFormLoadingState<D, E>) {
    onLoadingState(state);
  } else if (state is LyFormSuccessState<D, E>) {
    onSuccessState(state);
  } else if (state is LyFormErrorState<D, E>) {
    onErrorState(state);
  }
}