ValueStreamConsumer<M, T> class
ValueStreamConsumer exposes a builder and listener to react to new values from a stream.
ValueStreamConsumer is analogous to a nested ValueStreamListener and ValueStreamBuilder but reduces the amount of boilerplate needed.
ValueStreamConsumer requires stream.hasValue
to always be true
,
and the stream does not emit any error events.
See ValueStreamHasNoValueError
and UnhandledStreamError
for more information.
ValueStreamConsumer should only be used when it is necessary to both rebuild UI and execute other reactions to value changes in the stream.
ValueStreamConsumer takes a required ValueStream
,
ValueStreamWidgetListener
and ValueStreamWidgetBuilder
and an optional ValueStreamBuilderCondition
.
Example
ValueStreamConsumer<T>(
stream: valueStream,
listener: (context, previous, current) {
// do stuff here based on valueStream's
// previous and current values
},
builder: (context, value, child) {
// Build widget based on valueStream's value
},
child: const SizedBox(), // Optional child widget that remains stable
)
An optional buildWhen can be implemented for more
granular control over when builder is called.
The buildWhen will be invoked on each stream value
change.
It takes the previous value
and current value
and must return
a bool which determines whether or not the builder
function will be invoked.
The previous value
will be initialized to the value
of the stream when
the ValueStreamConsumer is initialized.
buildWhen is optional and if it isn't implemented,
it will default to true
.
child is optional but is good practice to use if part of the widget subtree does not depend on the value of the stream.
Example
ValueStreamConsumer<T>(
stream: valueStream,
listener: (context, previous, current) {
// do stuff here based on valueStream's
// previous and current values
},
buildWhen: (previous, current) {
// return true/false to determine whether or not
// to rebuild the widget with valueStream's value
},
builder: (context, value, child) {
// Build widget based on valueStream's value
},
child: const SizedBox(), // Optional child widget that remains stable
)
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatefulWidget
- ValueStreamConsumer
Constructors
-
ValueStreamConsumer.new({Key? key, required ValueStream<
M> stream, T? distinctBy(M event)?, required ValueStreamWidgetListener<M, T> listener, required ValueStreamWidgetBuilder<M> builder, ValueStreamBuilderCondition<M, T> ? buildWhen, Widget? child, bool isReplayValueStream = true}) -
ValueStreamConsumer exposes a builder and listener to react to new
values from a stream.
const
Properties
-
builder
→ ValueStreamWidgetBuilder<
M> -
The builder function which will be invoked on each widget build.
The builder takes the
BuildContext
and currentvalue
and must return a widget. This is analogous to the builder function in StreamBuilder.final -
buildWhen
→ ValueStreamBuilderCondition<
M, T> ? -
Takes the previous
value
and the currentvalue
and is responsible for returning a bool which determines whether or not to trigger builder with the currentvalue
.final - child → Widget?
-
A ValueStream-independent widget which is passed back to the builder.
final
- distinctBy → T? Function(M event)?
-
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- isReplayValueStream → bool
-
Whether or not the stream emits the last value
like
BehaviorSubject
does.final - key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
-
listener
→ ValueStreamWidgetListener<
M, T> -
Takes the
BuildContext
along with theprevious
andcurrent
values and is responsible for executing in response tovalue
changes.final - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
stream
→ ValueStream<
M> -
The ValueStream that the ValueStreamConsumer will interact with.
final
Methods
-
createElement(
) → StatefulElement -
Creates a StatefulElement to manage this widget's location in the tree.
inherited
-
createState(
) → State< ValueStreamConsumer< M, T> > -
Creates the mutable state for this widget at a given location in the tree.
override
-
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, int wrapWidth = 65}) → 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