ValueStreamListener<M, T> constructor
const
ValueStreamListener<M, T> ({
- Key? key,
- required ValueStream<
M> stream, - T? distinctBy(
- M event
- required ValueStreamWidgetListener<
M, T> listener, - required Widget child,
- 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,
});