FunctionaListener<T> extension Null safety

extension functions on ValueListenable that allows you to work with them almost as if it was a synchronous stream. Each extension function returns a new ValueNotifier that updates its value when the value of this changes You can chain these functions to build complex processing pipelines from a simple ValueListenable In the examples we use listen to react on value changes. Instead of applying listen you could also pass the end of the function chain to a ValueListenableBuilder

on

Methods

combineLatest<TIn2, TOut>(ValueListenable<TIn2> combineWith, CombiningFunction2<T, TIn2, TOut> combiner) ValueListenable<TOut>
Imagine having two ValueNotifier in you model and you want to update a certain region of the screen with their values every time one of them get updated. combineLatest combines two ValueListenable in that way that it returns a new ValueNotifier that changes its value of TOut whenever one of the input listenables this or combineWith updates its value. This new value is built by the combiner function that is called on any value change of the input listenables.
combineLatest3<TIn2, TIn3, TOut>(ValueListenable<TIn2> combineWith2, ValueListenable<TIn3> combineWith3, CombiningFunction3<T, TIn2, TIn3, TOut> combiner) ValueListenable<TOut>
Similar to what combineLatest does. Only change is you can listen to 3 ValueNotifiers together usage e.g: final subscription = listenable1
combineLatest4<TIn2, TIn3, TIn4, TOut>(ValueListenable<TIn2> combineWith2, ValueListenable<TIn3> combineWith3, ValueListenable<TIn4> combineWith4, CombiningFunction4<T, TIn2, TIn3, TIn4, TOut> combiner) ValueListenable<TOut>
Similar to what combineLatest does. Only change is you can listen to 4 ValueNotifiers together usage e.g: final subscription = listenable1
combineLatest5<TIn2, TIn3, TIn4, TIn5, TOut>(ValueListenable<TIn2> combineWith2, ValueListenable<TIn3> combineWith3, ValueListenable<TIn4> combineWith4, ValueListenable<TIn5> combineWith5, CombiningFunction5<T, TIn2, TIn3, TIn4, TIn5, TOut> combiner) ValueListenable<TOut>
Similar to what combineLatest does. Only change is you can listen to 5 ValueNotifiers together usage e.g: final subscription = listenable1
combineLatest6<TIn2, TIn3, TIn4, TIn5, TIn6, TOut>(ValueListenable<TIn2> combineWith2, ValueListenable<TIn3> combineWith3, ValueListenable<TIn4> combineWith4, ValueListenable<TIn5> combineWith5, ValueListenable<TIn6> combineWith6, CombiningFunction6<T, TIn2, TIn3, TIn4, TIn5, TIn6, TOut> combiner) ValueListenable<TOut>
Similar to what combineLatest does. Only change is you can listen to 6 ValueNotifiers together usage e.g: final subscription = listenable1 .combineLatest6<String, String, String, String, String, String>( listenable2, listenable3, listenable4, listenable5, listenable6, (i, j, k, l, m, s) => "$i:$j:$k:$l:$m:$s") .listen((x, _) { print(x); });
debounce(Duration timeOut) ValueListenable<T>
If you get too much value changes during a short time period and you don't want or can handle them all debounce can help you. If you add a debounce to your listenable processing pipeline the returned ValueListenable will not emit an updated value before at least timpeout time has passed since the last value change. All value changes before will be discarded.
listen(void handler(T, ListenableSubscription)) ListenableSubscription
let you work with a ValueListenable as it should be by installing a handler function that is called on any value change of this and gets the new value passed as an argument. It returns a subscription object that lets you stop the handler from being called by calling cancel() on the subscription. The handler get the subscription object passed on every call so that it is possible to uninstall the handler from the handler itself.
map<TResult>(TResult convert(T)) ValueListenable<TResult>
converts a ValueListenable to another type T by returning a new connected ValueListenable<T> on each value change of this the conversion function convert is called to do the type conversion
mergeWith(List<ValueListenable<T>> mergeWith) ValueListenable<T>
Merges value changes of this together with value changes of a List of ValueListenables so that when ever any of them changes the result of mergeWith will change too.
select<TResult>(TResult selector(T)) ValueListenable<TResult>
select allows you to set a filter on a ValueListenable like where, and the returned ValueListenable only emit a new value when the returned value of selector function change.
where(bool selector(T)) ValueListenable<T>
where allows you to set a filter on a ValueListenable so that an installed handler function is only called if the passed selector function returns true. Because the selector function is called on every new value you can change the filter during runtime.