onTransition method
Called whenever a transition occurs in any bloc with the given bloc
and 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.
Implementation
@override
void onTransition(
Bloc<dynamic, dynamic> bloc,
Transition<dynamic, dynamic> transition,
) {
super.onTransition(bloc, transition);
assert(() {
final context = CausalityZone.currentContext();
TrinityEventBus.instance.emit(CausalEvent(
parentId: context?.eventId,
type: CausalEventType.stateChange,
description: '${bloc.runtimeType}: ${transition.event.runtimeType}',
metadata: {
'bloc_type': bloc.runtimeType.toString(),
'event_type': transition.event.runtimeType.toString(),
'current_state_type': transition.currentState.runtimeType.toString(),
'next_state_type': transition.nextState.runtimeType.toString(),
},
));
return true;
}());
}