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
-
- Object
- CustomChangeNotifier
- CustomValueNotifier
- 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<
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.T> , provided by the FunctionaListener extension -
combineLatest<
TIn2, TOut> (ValueListenable< TIn2> combineWith, CombiningFunction2<T, TIn2, TOut> combiner, {bool lazy = false}) → ValueListenable<TOut> -
Available on ValueListenable<
Imagine having twoT> , provided by the FunctionaListener extensionValueNotifierin 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 twoValueListenablein that way that it returns a newValueNotifierthat changes its value ofTOutwhenever one of the input listenablesthisorcombineWithupdates its value. This new value is built by thecombinerfunction 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<
Similar to what combineLatest does. Only change is you can listen to 3 ValueNotifiers together usage e.g: final subscription = listenable1T> , provided by the FunctionaListener extension -
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<
Similar to what combineLatest does. Only change is you can listen to 4 ValueNotifiers together usage e.g: final subscription = listenable1T> , provided by the FunctionaListener extension -
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<
Similar to what combineLatest does. Only change is you can listen to 5 ValueNotifiers together usage e.g: final subscription = listenable1T> , provided by the FunctionaListener extension -
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<
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); });T> , provided by the FunctionaListener extension -
debounce(
Duration timeOut, {bool lazy = false}) → ValueListenable< T> -
Available on ValueListenable<
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 returnedT> , provided by the FunctionaListener extensionValueListenablewill not emit an updated value before at leasttimpeouttime 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<
let you work with aT> , provided by the FunctionaListener extensionValueListenableas it should be by installing ahandlerfunction that is called on any value change ofthisand gets the new value passed as an argument. It returns a subscription object that lets you stop thehandlerfrom being called by callingcancel()on the subscription. Thehandlerget the subscription object passed on every call so that it is possible to uninstall thehandlerfrom thehandleritself. -
listen(
void handler(ListenableSubscription)) → ListenableSubscription -
Available on Listenable, provided by the FunctionaListener2 extension
let you work with aListenableas it should be by installing ahandlerfunction that is called on any value change ofthisand gets the new value passed as an argument. It returns a subscription object that lets you stop thehandlerfrom being called by callingcancel()on the subscription. Thehandlerget the subscription object passed on every call so that it is possible to uninstall thehandlerfrom thehandleritself. -
map<
TResult> (TResult convert(T), {bool lazy = false}) → ValueListenable< TResult> -
Available on ValueListenable<
converts a ValueListenable to another typeT> , provided by the FunctionaListener extensionTby returning a new connectedValueListenable<T>on each value change ofthisthe conversion functionconvertis called to do the type conversion -
mergeWith(
List< ValueListenable< mergeWith, {bool lazy = false}) → ValueListenable<T> >T> -
Available on ValueListenable<
Merges value changes ofT> , provided by the FunctionaListener extensionthistogether with value changes of a List ofValueListenablesso that when ever any of them changes the result ofmergeWithwill 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<
select allows you to set a filter on aT> , provided by the FunctionaListener extensionValueListenablelike where, and the returnedValueListenableonly emit a new value when the returned value ofselectorfunction 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<
where allows you to set a filter on aT> , provided by the FunctionaListener extensionValueListenableso that an installed handler function is only called if the passedselectorfunction 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