LidConsumer<S> class
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
}
)
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatelessWidget
- LidConsumer
Constructors
-
LidConsumer({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
andLidBuilder
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.const
Properties
- animate → bool
-
Animates when change state, using AnimatedSwitcher
final
-
builder
→ LidWidgetBuilder<
S> -
The builder function which will be invoked on each widget build.
The builder takes the
BuildContext
and currentstate
and must return a widget. This is analogous to the builder function in StreamBuilder.final -
buildWhen
→ BuilderCondition<
S> ? -
Takes the previous
state
and the currentstate
and is responsible for returning a bool which determines whether or not to trigger builder with the currentstate
.final - duration → Duration
-
The duration of the animation
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
-
listener
→ LidWidgetListener<
S> -
Takes the
BuildContext
along with the stateNotifierstate
and is responsible for executing in response tostate
changes.final -
listenWhen
→ ListenerCondition<
S> ? -
Takes the previous
state
and the currentstate
and is responsible for returning a bool which determines whether or not to call listener of LidConsumer with the currentstate
.final - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
stateNotifier
→ StateNotifier<
S> -
The stateNotifier that the LidConsumer will interact with.
final
- transitionBuilder → AnimatedSwitcherTransitionBuilder
-
Type of the animation, the default animation is FadeIn
final
Methods
-
build(
BuildContext context) → Widget -
Describes the part of the user interface represented by this widget.
override
-
createElement(
) → StatelessElement -
Creates a StatelessElement to manage this widget's location in the tree.
inherited
-
debugDescribeChildren(
) → List< DiagnosticsNode> -
Returns a list of DiagnosticsNode objects describing this node's
children.
inherited
-
debugFillProperties(
DiagnosticPropertiesBuilder properties) → void -
Add additional properties associated with the node.
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toDiagnosticsNode(
{String? name, DiagnosticsTreeStyle? style}) → DiagnosticsNode -
Returns a debug representation of the object that is used by debugging
tools and by DiagnosticsNode.toStringDeep.
inherited
-
toString(
{DiagnosticLevel minLevel = DiagnosticLevel.info}) → String -
A string representation of this object.
inherited
-
toStringDeep(
{String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String -
Returns a string representation of this node and its descendants.
inherited
-
toStringShallow(
{String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String -
Returns a one-line detailed description of the object.
inherited
-
toStringShort(
) → String -
A short, textual description of this widget.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited