MultiBlocListener constructor
Merges multiple BlocListener widgets into one widget tree.
MultiBlocListener improves the readability and eliminates the need to nest multiple BlocListeners.
By using MultiBlocListener we can go from:
BlocListener<BlocA, BlocAState>(
listener: (context, state) {},
child: BlocListener<BlocB, BlocBState>(
listener: (context, state) {},
child: BlocListener<BlocC, BlocCState>(
listener: (context, state) {},
child: ChildA(),
),
),
)
to:
MultiBlocListener(
listeners: [
BlocListener<BlocA, BlocAState>(
listener: (context, state) {},
),
BlocListener<BlocB, BlocBState>(
listener: (context, state) {},
),
BlocListener<BlocC, BlocCState>(
listener: (context, state) {},
),
],
child: ChildA(),
)
MultiBlocListener converts the BlocListener list into a tree of nested BlocListener widgets. As a result, the only advantage of using MultiBlocListener is improved readability due to the reduction in nesting and boilerplate.
Implementation
MultiBlocListener({
required List<SingleChildWidget> listeners,
required Widget child,
Key? key,
}) : super(key: key, providers: listeners, child: child);