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