CustomValueNotifier<T> class

Sometimes you want a ValueNotifier where you can control when its listeners are notified. With the CustomValueNotifier you can do this: If you pass CustomNotifierMode.always for the mode parameter, notifierListeners will be called everytime you assign a value to the value property independent of if the value is different from the previous one. If you pass CustomNotifierMode.manual for the mode parameter, notifierListeners will not be called when you assign a value to the value property. You have to call it manually to notify the Listeners. Aditionally it has a listenerCount property that tells you how many listeners are currently listening to the notifier.

Inheritance
Implemented types
Available extensions

Constructors

CustomValueNotifier(T initialValue, {CustomNotifierMode mode = CustomNotifierMode.normal, bool asyncNotification = false, void onError(Object error, StackTrace stackTrace)?})

Properties

asyncNotification bool
If true, the listeners will be notified asynchronously, which can be helpful if you encounter problems that you trigger rebuilds during the build phase.
final
hashCode int
The hash code for this object.
no setterinherited
hasListeners bool
Whether any listeners are currently registered.
no setterinherited
listenerCount int
getter/setter pair
mode CustomNotifierMode
final
onError → void Function(Object error, StackTrace stackTrace)?
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
value ↔ T
The current value of the object. When the value changes, the callbacks registered with addListener will be invoked.
getter/setter pairoverride-getter

Methods

addListener(void listener()) → void
Register a closure to be called when the object changes.
override
async({bool lazy = false}) ValueListenable<T>

Available on ValueListenable<T>, provided by the FunctionaListener extension

ValueListenable are inherently synchronous. In most cases this is what you want. But if for example your ValueListenable gets updated inside a build method of a widget which would trigger a rebuild because your widgets is listening to the ValueListenable you get an exception that you called setState inside a build method. By using async you push the update of the ValueListenable to the next frame. This way you can update the ValueListenable inside a build method without getting an exception.
combineLatest<TIn2, TOut>(ValueListenable<TIn2> combineWith, CombiningFunction2<T, TIn2, TOut> combiner, {bool lazy = false}) ValueListenable<TOut>

Available on ValueListenable<T>, provided by the FunctionaListener extension

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, {bool lazy = false}) ValueListenable<TOut>

Available on ValueListenable<T>, provided by the FunctionaListener extension

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, {bool lazy = false}) ValueListenable<TOut>

Available on ValueListenable<T>, provided by the FunctionaListener extension

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, {bool lazy = false}) ValueListenable<TOut>

Available on ValueListenable<T>, provided by the FunctionaListener extension

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, {bool lazy = false}) ValueListenable<TOut>

Available on ValueListenable<T>, provided by the FunctionaListener extension

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, {bool lazy = false}) ValueListenable<T>

Available on ValueListenable<T>, provided by the FunctionaListener extension

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.
debounce(Duration timeOut) Listenable

Available on Listenable, provided by the FunctionaListener2 extension

dispose() → void
Discards any resources used by the object. After this is called, the object is not in a usable state and should be discarded (calls to addListener will throw after the object is disposed).
override
listen(void handler(T, ListenableSubscription)) ListenableSubscription

Available on ValueListenable<T>, provided by the FunctionaListener extension

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.
listen(void handler(ListenableSubscription)) ListenableSubscription

Available on Listenable, provided by the FunctionaListener2 extension

let you work with a Listenable 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), {bool lazy = false}) ValueListenable<TResult>

Available on ValueListenable<T>, provided by the FunctionaListener extension

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, {bool lazy = false}) ValueListenable<T>

Available on ValueListenable<T>, provided by the FunctionaListener extension

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.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
notifyListeners([void onError(Object error, StackTrace stackTrace)?]) → void
Call all the registered listeners.
override
removeListener(void listener()) → void
Remove a previously registered closure from the list of closures that are notified when the object changes.
override
select<TResult>(TResult selector(T), {bool lazy = false}) ValueListenable<TResult>

Available on ValueListenable<T>, provided by the FunctionaListener extension

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. With this you can react on a specific value change of a property of the ValueListenable.
toString() String
A string representation of this object.
inherited
where(bool selector(T), {T? fallbackValue, bool lazy = false}) ValueListenable<T>

Available on ValueListenable<T>, provided by the FunctionaListener extension

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.

Operators

operator ==(Object other) bool
The equality operator.
inherited