When a Cubit emits a new state, a Change occurs. We can observe all changes for a given Cubit by overriding onChange.
class CounterCubit extends Cubit<int> {
CounterCubit() : super(0);
void increment() => emit(state + 1);
@override
void onChange(Change<int> change) {
super.onChange(change);
print(change);
}
}Copy to clipboardErrorCopied
We can then interact with the Cubit
and observe all changes output to the console.
void main() {
CounterCubit()
..increment()
..close();
}Copy to clipboardErrorCopied
The above example would output:
Change { currentState: 0, nextState: 1 }