BlocSideEffectListener<B extends SideEffectProvider<C> , C> constructor
const
BlocSideEffectListener<B extends SideEffectProvider<C> , C> ({
- Key? key,
- required BlocWidgetSideEffectListener<
C> listener, - B? bloc,
- Widget? child,
Takes a BlocWidgetSideEffectListener and an optional bloc
and invokes
the listener
in response to side effect
emits in the bloc
.
It should be used for functionality that needs to occur only in response to
a side effect
emit such as navigation, showing a SnackBar
, showing
a Dialog
, etc...
The listener
is guaranteed to only be called once for each side effect
.
If the bloc
parameter is omitted, BlocListener
will automatically
perform a lookup using BlocProvider
and the current BuildContext
.
BlocSideEffectListener<BlocA, BlocASideEffect>(
listener: (context, sideEffect) {
// do stuff here based on BlocA's side effect
},
child: Container(),
)
Only specify the bloc
if you wish to provide a bloc
that is otherwise
not accessible via BlocProvider
and the current BuildContext
.
BlocSideEffectListener<BlocA, BlocASideEffect>(
value: blocA,
listener: (context, sideEffect) {
// do stuff here based on BlocA's side effect
},
child: Container(),
)
Implementation
const BlocSideEffectListener({
Key? key,
required BlocWidgetSideEffectListener<C> listener,
B? bloc,
Widget? child,
}) : super(
key: key,
child: child,
listener: listener,
bloc: bloc,
);