Bloc Observer
Global observer that receives lifecycle notifications from every Bloc and Cubit in the app.
Set a custom subclass once at app startup, before any Blocs are created:
class App : Application() {
override fun onCreate() {
super.onCreate()
BlocObserver.shared = AppBlocObserver()
}
}Content copied to clipboard
Hook summary
| Hook | When it fires | Emitter type |
|---|---|---|
| onCreate | Emitter is initialised | Bloc + Cubit |
| onEvent | Before an event is dispatched | Bloc only |
| onChange | After every emit() | Bloc + Cubit |
| onTransition | After a synchronous emit() with event context | Bloc only |
| onError | When addError() is called | Bloc + Cubit |
| onClose | When close() is called | Bloc + Cubit |
Always call super in every override so the chain remains intact as the library grows.
Functions
Link copied to clipboard
Called when Cubit.close / Bloc.close completes.
Link copied to clipboard
Called whenever Cubit.addError / Bloc.addError is invoked.
Link copied to clipboard