ValueStreamListener<M, T> constructor

const ValueStreamListener<M, T>({
  1. Key? key,
  2. required ValueStream<M> stream,
  3. T? distinctBy(
    1. M event
    )?,
  4. required ValueStreamWidgetListener<M, T> listener,
  5. required Widget child,
  6. bool isReplayValueStream = true,
})

Takes a ValueStreamWidgetListener and a stream and invokes the listener in response to value changes in the stream.

It should be used for functionality that needs to occur only in response to a value change such as navigation, showing a SnackBar, showing a Dialog, etc...

The listener is guaranteed to only be called once for each value change unlike the builder in ValueStreamBuilder.

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

Example

ValueStreamListener<T>(
  stream: valueStream,
  listener: (context, previous, current) {
    // do stuff here based on valueStream's
    // previous and current values
  },
  child: Container(),
)

Implementation

const ValueStreamListener({
  super.key,
  required this.stream,
  this.distinctBy,
  required this.listener,
  required this.child,
  this.isReplayValueStream = true,
});