Skip to content

Instantly share code, notes, and snippets.

@saliouseck2009
Last active February 25, 2022 13:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saliouseck2009/79072c694996bc4dc8b711d33f323f8c to your computer and use it in GitHub Desktop.
Save saliouseck2009/79072c694996bc4dc8b711d33f323f8c to your computer and use it in GitHub Desktop.
BlocObserver usage on flutter_bloc v8.0.0
class SimpleBlocObserver extends BlocObserver {
@override
void onEvent(Bloc bloc, Object? event) {
super.onEvent(bloc, event);
print(event);
}
@override
void onTransition(Bloc bloc, Transition transition) {
super.onTransition(bloc, transition);
print(transition);
}
@override
void onError(BlocBase bloc, Object error, StackTrace stackTrace) {
super.onError(bloc, error, stackTrace);
print(error);
}
@override
void onChange(BlocBase bloc, Change change) {
super.onChange(bloc, change);
print(change);
}
}
//in main function call the class to observe the hole bloc activity in the console.
BlocOverrides.runZoned(() {
runApp(const MyApp());
}, blocObserver: SimpleBlocObserver());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment