Hi !
I think there's a problem with the documentation, specifically the BlocObserver part (https://bloclibrary.dev/#/coreconcepts?id=blocobserver-1).
The problem is, The doc is advising user to call the SimpleBlocObserver as a Bloc in main.dart but If you check the BlocObserver's class which is extended by SimpleBlocObserver, this is not a Bloc. So it cannot work.
What can we do to create a "generic" bloc to logg everything straight out any bloc ?
Thanks !
KBZH
Hi @Kobreizhyashi 馃憢
The doc is only advising the user to instantiate the observer in main.dart
: Bloc.observer = SimpleBlocObserver();
What can we do to create a "generic" bloc to logg everything straight out any bloc ?
You need to create a class like:
class SimpleBlocObserver extends BlocObserver {
@override
void onChange(Cubit cubit, Change change) {
print('${cubit.runtimeType} $change');
super.onChange(cubit, change);
}
@override
void onTransition(Bloc bloc, Transition transition) {
print('${bloc.runtimeType} $transition');
super.onTransition(bloc, transition);
}
@override
void onError(Cubit cubit, Object error, StackTrace stackTrace) {
print('${cubit.runtimeType} $error $stackTrace');
super.onError(cubit, error, stackTrace);
}
}
and instantiate in main.dart
:
void main() {
Bloc.observer = SimpleBlocObserver();
}
Thanks for your reply !
Oh yeah, I didn't saw the dot before observer (Bloc . observer) due to the (too much) dark mode.
Sorry !
Most helpful comment
Thanks for your reply !
Oh yeah, I didn't saw the dot before observer (Bloc . observer) due to the (too much) dark mode.
Sorry !