Hi @felangel ,
I found if we override onTransition and onChange in BlocObserver(If we apply both cubit and bloc in the app), it will call onTransition and then call onChange. In my case, the console will print transition info and then print change info, which is highly duplicate.
I understood bloc now is built on the cubit, so the onChange should be called, but is it possible when the onTransition is called, the onChange will not be called again?
Hi @Peng-Qian 馃憢
Thanks for opening an issue!
This is intentional because it would be very strange for onChange to not function for blocs and it is also used by other packages like hydrated_bloc
to ensure compatibility between the two. If you don't want onChange to fire for blocs you can just update your BlocObserver
:
class MyBlocObserver extends BlocObserver {
void onChange(Cubit cubit, Change change) {
if (cubit is! Bloc) print(change);
super.onChange(cubit, change);
}
}
Hope that helps 馃憤
Many thx!
Most helpful comment
Hi @Peng-Qian 馃憢
Thanks for opening an issue!
This is intentional because it would be very strange for onChange to not function for blocs and it is also used by other packages like
hydrated_bloc
to ensure compatibility between the two. If you don't want onChange to fire for blocs you can just update yourBlocObserver
:Hope that helps 馃憤