MultiLidListener constructor
MultiLidListener({
- Key? key,
- required List<
LidListener> listeners, - required Widget child,
Merges multiple LidListener widgets into one widget tree.
LidCubitListener
improves the readability and eliminates the need
to nest multiple LidListeners.
By using MultiLidListener we can go from:
LidListener<StateType>(
listener: (context, state) {},
child: LidListener<StateType>(
stateNotifier: stateNotifier,
listener: (context, state) {},
child: LidListener<StateType>(
stateNotifier: stateNotifier,
listener: (context, state) {},
child: ChildA(),
),
),
)
to:
MultiLidListener(
listeners: [
LidListener<StateType>(
stateNotifier: stateNotifier,
listener: (context, state) {},
),
LidListener<StateType>(
stateNotifier: stateNotifier,
listener: (context, state) {},
),
LidListener<StateType>(
stateNotifier: stateNotifier,
listener: (context, state) {},
),
],
child: ChildA(),
)
MultiLidListener converts the LidListener list into a tree of nested LidListener widgets. As a result, the only advantage of using MultiLidListener is improved readability due to the reduction in nesting and boilerplate.
Implementation
MultiLidListener({
Key? key,
required List<LidListener> listeners,
required Widget child,
}) : super(
key: key,
children: listeners,
child: child,
);