onTransitionBloc method
void
onTransitionBloc(
- Bloc bloc,
- Transition transition
Implementation
void onTransitionBloc(Bloc bloc, Transition transition) async {
if (!enabled) {
_logDebug("Inspector is disabled");
return;
}
String? data;
try {
data = json.encode(
InvestigativePacket(
type: PacketType.blocTransitioned,
blocName: bloc.runtimeType.toString(),
identity: identity,
blocChange: BlocChange(
blocName: bloc.runtimeType.toString(),
eventName: transition.event.runtimeType.toString(),
oldState: transition.currentState.toJson(),
newState: transition.nextState.toJson(),
),
),
);
} on NoSuchMethodError catch (error) {
data = json.encode(
InvestigativePacket(
type: PacketType.blocFallbackTransitioned,
identity: identity,
decodeErrorReason: error.toString(),
blocName: bloc.runtimeType.toString(),
oldFallbackState: transition.currentState.toString(),
newFallbackState: transition.nextState.toString(),
blocChange: BlocChange(
blocName: bloc.runtimeType.toString(),
eventName: transition.event.runtimeType.toString(),
)),
);
} on JsonUnsupportedObjectError catch (error) {
data = json.encode(
InvestigativePacket(
type: PacketType.blocFallbackTransitioned,
identity: identity,
blocName: bloc.runtimeType.toString(),
oldFallbackState: transition.currentState.toString(),
newFallbackState: transition.nextState.toString(),
decodeErrorReason: error.cause.toString(),
blocChange: BlocChange(
blocName: bloc.runtimeType.toString(),
eventName: transition.event.runtimeType.toString(),
)),
);
} catch (error) {
logger.e(error);
}
if (data != null) {
await _sendLog(data);
}
}