onChange method

  1. @protected
  2. @mustCallSuper
void onChange(
  1. Change<Connection> change

Called whenever a change occurs with the given change. A change occurs when a new state is emitted. onChange is called before the state of the cubit is updated. onChange is a great spot to add logging/analytics for a specific cubit.

Note: super.onChange should always be called first.

void onChange(Change change) {
  // Always call super.onChange with the current change

  // Custom onChange logic goes here

See also:

  • BlocObserver for observing Cubit behavior globally.


void onChange(Change<State> change) {
  // ignore: invalid_use_of_protected_member
  _blocObserver.onChange(this, change);