ValueStreamBuilder<M, T> class

ValueStreamBuilder handles building a widget in response to new value. ValueStreamBuilder is analogous to StreamBuilder but has simplified API to reduce the amount of boilerplate code needed as well as ValueStream-specific performance improvements.

ValueStreamBuilder requires stream.hasValue to always be true, and the stream does not emit any error events. See ValueStreamHasNoValueError and UnhandledStreamError for more information.

Please refer to ValueStreamListener if you want to "do" anything in response to value changes such as navigation, showing a dialog, etc...

ValueStreamBuilder handles building a widget in response to new value. ValueStreamBuilder is analogous to StreamBuilder but has simplified API to reduce the amount of boilerplate code needed as well as ValueStream-specific performance improvements.

Example

ValueStreamBuilder<T>(
  stream: valueStream,
  builder: (context, value, child) {
    // return widget here 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 how often ValueStreamBuilder rebuilds.

  • buildWhen should only be used for performance optimizations as it provides no security about the value passed to the builder function.
  • buildWhen will be invoked on each stream value change.
  • buildWhen 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 ValueStreamBuilder is initialized.

buildWhen is optional and if omitted, 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

ValueStreamBuilder<T>(
  stream: valueStream,
  buildWhen: (previous, current) {
    // return true/false to determine whether or not
    // to rebuild the widget with valueStream's value
  },
  builder: (context, value, child) {
    // return widget here based on valueStream's value
  },
  child: const SizedBox(), // Optional child widget that remains stable
)
Inheritance

Constructors

ValueStreamBuilder.new({Key? key, required ValueStream<M> stream, T? distinctBy(M event)?, required ValueStreamWidgetBuilder<M> builder, ValueStreamBuilderCondition<M, T>? buildWhen, Widget? child, bool isReplayValueStream = true})
ValueStreamBuilder handles building a widget in response to new value. ValueStreamBuilder is analogous to StreamBuilder but has simplified API to reduce the amount of boilerplate code needed as well as ValueStream-specific performance improvements.
const

Properties

builder ValueStreamWidgetBuilder<M>
The builder function which will be invoked on each widget build. The builder takes the BuildContext and current value 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 current value and is responsible for returning a bool which determines whether or not to trigger builder with the current value.
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
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
stream ValueStream<M>
The ValueStream that the ValueStreamBuilder will interact with.
final

Methods

createElement() StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
inherited
createState() State<ValueStreamBuilder<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