LidConsumer<S> constructor
- Key? key,
- required LidWidgetListener<
S> listener, - required StateNotifier<
S> stateNotifier, - required LidWidgetBuilder<
S> builder, - ListenerCondition<
S> ? listenWhen, - BuilderCondition<
S> ? buildWhen, - bool animate = false,
- AnimatedSwitcherTransitionBuilder transitionBuilder = AnimatedSwitcher.defaultTransitionBuilder,
- Duration duration = const Duration(milliseconds: 300),
LidConsumer exposes a builder and listener in order react to new
states.
LidConsumer is analogous to a nested LidListener
and LidBuilder
but reduces the amount of boilerplate needed.
LidConsumer should only be used when it is necessary to both rebuild UI
and execute other reactions to state changes in the stateNotifier.
LidConsumer takes a required LidWidgetBuilder
and CubitWidgetListener
and stateNotifier and an optional
LidBuilderCondition
, and LidListenerCondition
.
LidConsumer<StateType>(
stateNotifier: stateNotifier,
listener: (context, state) {
// do stuff here based on State Notifier's state
},
builder: (context, state) {
// return widget here based on State Notifier's state
}
)
An optional listenWhen and buildWhen can be implemented for more
granular control over when listener and builder are called.
The listenWhen and buildWhen will be invoked on each stateNotifier state
change.
They each take the previous state
and current state
and must return
a bool which determines whether or not the builder and/or listener
function will be invoked.
The previous state
will be initialized to the state
of the stateNotifier when
the LidConsumer is initialized.
listenWhen is optional and if it isn't implemented,
it will default to true
.
buildWhen is optional and if omitted, it will default true
if previous
state
is different current state
, otherwise is false
, however the
first time does not have an effect, always true
.
CubitConsumer<CubitA, CubitAState>(
stateNotifier: stateNotifier,
listenWhen: (previous, current) {
// return true/false to determine whether or not
// to invoke listener with state
},
listener: (context, state) {
// do stuff here based on State Notifier's state
},
buildWhen: (previous, current) {
// return true/false to determine whether or not
// to rebuild the widget with state
},
builder: (context, state) {
// return widget here based on State Notifier's state
}
)
Implementation
const LidConsumer({
Key? key,
required this.listener,
required this.stateNotifier,
required this.builder,
this.listenWhen,
this.buildWhen,
this.animate = false,
this.transitionBuilder = AnimatedSwitcher.defaultTransitionBuilder,
this.duration = const Duration(milliseconds: 300),
}) : super(key: key);