Line data Source code
1 : import 'package:bloc/bloc.dart'; 2 : import 'package:meta/meta.dart'; 3 : 4 : /// An interface for observing the behavior of [Bloc] instances. 5 : class BlocObserver { 6 : /// Called whenever a [Bloc] is instantiated. 7 : /// In many cases, a cubit may be lazily instantiated and 8 : /// [onCreate] can be used to observe exactly when the cubit 9 : /// instance is created. 10 6 : @protected 11 : @mustCallSuper 12 : void onCreate(BlocBase bloc) {} 13 : 14 : /// Called whenever an [event] is `added` to any [bloc] with the given [bloc] 15 : /// and [event]. 16 4 : @protected 17 : @mustCallSuper 18 : void onEvent(Bloc bloc, Object? event) {} 19 : 20 : /// Called whenever a [Change] occurs in any [bloc] 21 : /// A [change] occurs when a new state is emitted. 22 : /// [onChange] is called before a bloc's state has been updated. 23 3 : @protected 24 : @mustCallSuper 25 : void onChange(BlocBase bloc, Change change) {} 26 : 27 : /// Called whenever a transition occurs in any [bloc] with the given [bloc] 28 : /// and [transition]. 29 : /// A [transition] occurs when a new `event` is `added` and `mapEventToState` 30 : /// executed. 31 : /// [onTransition] is called before a [bloc]'s state has been updated. 32 3 : @protected 33 : @mustCallSuper 34 : void onTransition(Bloc bloc, Transition transition) {} 35 : 36 : /// Called whenever an [error] is thrown in any [Bloc] or [Cubit]. 37 : /// The [stackTrace] argument may be [StackTrace.empty] if an error 38 : /// was received without a stack trace. 39 2 : @protected 40 : @mustCallSuper 41 : void onError(BlocBase bloc, Object error, StackTrace stackTrace) {} 42 : 43 : /// Called whenever a [Bloc] is closed. 44 : /// [onClose] is called just before the [Bloc] is closed 45 : /// and indicates that the particular instance will no longer 46 : /// emit new states. 47 4 : @protected 48 : @mustCallSuper 49 : void onClose(BlocBase bloc) {} 50 : }