VN<T> class

A simplified and enhanced abstraction for working with ValueNotifier.

The VN class streamlines the use of ValueNotifier, adding flexibility through custom change types and advanced features such as merging multiple VN instances.

Features:

  • Customizable change behaviors via ChangeType.
  • Built-in listener management.
  • Easy merging of two VN instances into a single, derived VN.
  • Utility methods for notifying listeners, silent updates, and conditional updates.

Parameters:

  • T - The type of the value managed by this VN instance.
Implemented types
Mixed-in types
Available extensions

Constructors

VN(T initialValue, [ChangeType changeType = ChangeType.smart])
Creates a VN instance with an initial value and optional change behavior.

Properties

changeType ChangeType
The change behavior applied to this VN.
final
first → T

Available on VN<Iterable<T>>, provided by the BetterIterableNotifications extension

Returns the first element in the iterable.
no setter
first → T

Available on VN<Set<T>>, provided by the BetterSetNotifications extension

Returns the first element in the set.
no setter
firstOrNull → T?

Available on VN<Iterable<T>>, provided by the BetterIterableNotifications extension

Returns the first element in the iterable, or null if the iterable is empty.
no setter
firstOrNull → T?

Available on VN<Set<T>>, provided by the BetterSetNotifications extension

Returns the first element in the set, or null if the set is empty.
no setter
hashCode int
The hash code for this object.
no setterinherited
hasListeners bool
Indicates whether this VN has active listeners.
no setteroverride
isEmpty bool

Available on VN<Iterable<T>>, provided by the BetterIterableNotifications extension

Returns true if the iterable has no elements.
no setter
isEmpty bool

Available on VN<Map<K, V>>, provided by the BetterMapNotifications extension

Returns true if the map has no key-value pairs.
no setter
isEmpty bool

Available on VN<Set<T>>, provided by the BetterSetNotifications extension

Returns true if the set has no elements.
no setter
isNotEmpty bool

Available on VN<Iterable<T>>, provided by the BetterIterableNotifications extension

Returns true if the iterable has one or more elements.
no setter
isNotEmpty bool

Available on VN<Map<K, V>>, provided by the BetterMapNotifications extension

Returns true if the map has one or more key-value pairs.
no setter
isNotEmpty bool

Available on VN<Set<T>>, provided by the BetterSetNotifications extension

Returns true if the set has one or more elements.
no setter
keys Iterable<K>

Available on VN<Map<K, V>>, provided by the BetterMapNotifications extension

Returns an iterable of all keys in the map.
no setter
last → T

Available on VN<Iterable<T>>, provided by the BetterIterableNotifications extension

Returns the last element in the iterable.
no setter
last → T

Available on VN<Set<T>>, provided by the BetterSetNotifications extension

Returns the last element in the set.
no setter
lastOrNull → T?

Available on VN<Iterable<T>>, provided by the BetterIterableNotifications extension

Returns the last element in the iterable, or null if the iterable is empty.
no setter
lastOrNull → T?

Available on VN<Set<T>>, provided by the BetterSetNotifications extension

Returns the last element in the set, or null if the set is empty.
no setter
length int

Available on VN<Iterable<T>>, provided by the BetterIterableNotifications extension

Returns the number of elements in the iterable.
no setter
length int

Available on VN<Map<K, V>>, provided by the BetterMapNotifications extension

Returns the number of key-value pairs in the map.
no setter
length int

Available on VN<Set<T>>, provided by the BetterSetNotifications extension

Returns the number of elements in the set.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
value ↔ T
Gets the current value of this VN.
getter/setter pairoverride-getter
values Iterable<V>

Available on VN<Map<K, V>>, provided by the BetterMapNotifications extension

Returns an iterable of all values in the map.
no setter

Methods

add(T value) bool

Available on VN<Set<T>>, provided by the BetterSetNotifications extension

Adds the given value to the set.
addAll(Iterable<T> values) → void

Available on VN<Set<T>>, provided by the BetterSetNotifications extension

Adds all elements from the given values to the set.
addListener(VoidCallback listener) → void
Register a closure to be called when the object changes.
inherited
clear() → void

Available on VN<Set<T>>, provided by the BetterSetNotifications extension

Removes all elements from the set.
clear() → void

Available on VN<Map<K, V>>, provided by the BetterMapNotifications extension

Removes all key-value pairs from the map.
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).
inherited
firstWhere(bool function(T function)) → T

Available on VN<Set<T>>, provided by the BetterSetNotifications extension

Returns the first element that satisfies the given predicate function.
firstWhere(bool function(T)) → T

Available on VN<Iterable<T>>, provided by the BetterIterableNotifications extension

Returns the first element that satisfies the given predicate function.
hardAdd(T value) → void

Available on VN<List<T>>, provided by the BetterListNotifications extension

Adds the given value to the list and notifies listeners.
hardAddAll(Iterable<T> value) → void

Available on VN<List<T>>, provided by the BetterListNotifications extension

Appends all elements from the given iterable value to the list and notifies listeners.
hardClear() → void

Available on VN<Set<T>>, provided by the BetterSetNotifications extension

Removes all elements from the set and notifies listeners.
hardClear() → void

Available on VN<Map<K, V>>, provided by the BetterMapNotifications extension

Removes all key-value pairs from the map and notifies listeners.
hardRemove(Object? value) bool

Available on VN<List<T>>, provided by the BetterListNotifications extension

Removes the first occurrence of the given value from the list and notifies listeners.
hardRemove(Object? value) bool

Available on VN<Set<T>>, provided by the BetterSetNotifications extension

Removes the given value from the set and notifies listeners.
hardRemove(K key) → V?

Available on VN<Map<K, V>>, provided by the BetterMapNotifications extension

Removes the key-value pair with the given key from the map and notifies listeners.
hardRemoveAt(int index) → T

Available on VN<List<T>>, provided by the BetterListNotifications extension

Removes the element at the specified index from the list and notifies listeners.
hardRemoveWhere(bool where(T)) → void

Available on VN<Set<T>>, provided by the BetterSetNotifications extension

Removes all elements from the set that satisfy the predicate where and notifies listeners.
hardRemoveWhere(bool where(K key, V value)) → void

Available on VN<Map<K, V>>, provided by the BetterMapNotifications extension

Removes all key-value pairs from the map that satisfy the predicate where and notifies listeners.
hardRemoveWhere(bool where(T)) → void

Available on VN<List<T>>, provided by the BetterListNotifications extension

Removes all elements that satisfy the given predicate where and notifies listeners.
hardSet(T newValue) → void
Updates the value and notifies listeners unconditionally.
lastWhere(bool function(T function)) → T

Available on VN<Set<T>>, provided by the BetterSetNotifications extension

Returns the last element that satisfies the given predicate function.
lastWhere(bool function(T)) → T

Available on VN<Iterable<T>>, provided by the BetterIterableNotifications extension

Returns the last element that satisfies the given predicate function.
map<K2, V2>(MapEntry<K2, V2> converter(K k, V v)) Map<K2, V2>

Available on VN<Map<K, V>>, provided by the BetterMapNotifications extension

Transforms the map by applying a function to all its key-value pairs.
map<R>(R map(T e)) Iterable<R>

Available on VN<Set<T>>, provided by the BetterSetNotifications extension

Transforms the set by applying a function to all its elements.
merge<K, R>(VN<R> other, K initialValue, void listener(T left, R right, void emitter(K value))) VN<K>
Merges this VN with another VN into a derived VN.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
notify() → void
Notifies all listeners about a change in value.
notifyListeners() → void
Call all the registered listeners.
inherited
remove(K key) → V?

Available on VN<Map<K, V>>, provided by the BetterMapNotifications extension

Removes the key-value pair with the given key from the map.
remove(Object? value) bool

Available on VN<Set<T>>, provided by the BetterSetNotifications extension

Removes the given value from the set.
removeListener(VoidCallback listener) → void
Remove a previously registered closure from the list of closures that are notified when the object changes.
inherited
removeWhere(bool where(K key, V value)) → void

Available on VN<Map<K, V>>, provided by the BetterMapNotifications extension

Removes all key-value pairs from the map that satisfy the given predicate where.
removeWhere(bool where(T)) → void

Available on VN<Set<T>>, provided by the BetterSetNotifications extension

Removes all elements from the set that satisfy the given predicate where.
silentAdd(T value) → void

Available on VN<List<T>>, provided by the BetterListNotifications extension

Adds the given value to the list without notifying listeners.
silentAdd(T value) bool

Available on VN<Set<T>>, provided by the BetterSetNotifications extension

Adds the given value to the set without notifying listeners.
silentAddAll(Iterable<T> value) → void

Available on VN<List<T>>, provided by the BetterListNotifications extension

Appends all elements from the given iterable value to the list without notifying listeners.
silentAddAll(Iterable<T> values) → void

Available on VN<Set<T>>, provided by the BetterSetNotifications extension

Adds all elements from the given values to the set without notifying listeners.
silentClear() → void

Available on VN<Map<K, V>>, provided by the BetterMapNotifications extension

Removes all key-value pairs from the map without notifying listeners.
silentClear() → void

Available on VN<Set<T>>, provided by the BetterSetNotifications extension

Removes all elements from the set without notifying listeners.
silentRemove(Object? value) bool

Available on VN<List<T>>, provided by the BetterListNotifications extension

Removes the first occurrence of the given value from the list without notifying listeners.
silentRemove(Object? value) bool

Available on VN<Set<T>>, provided by the BetterSetNotifications extension

Removes the given value from the set without notifying listeners.
silentRemove(K key) → V?

Available on VN<Map<K, V>>, provided by the BetterMapNotifications extension

Removes the key-value pair with the given key from the map without notifying listeners.
silentRemoveAt(int index) → T

Available on VN<List<T>>, provided by the BetterListNotifications extension

Removes the element at the specified index from the list without notifying listeners.
silentRemoveWhere(bool where(T)) → void

Available on VN<List<T>>, provided by the BetterListNotifications extension

Removes all elements that satisfy the given predicate where without notifying listeners.
silentRemoveWhere(bool where(K key, V value)) → void

Available on VN<Map<K, V>>, provided by the BetterMapNotifications extension

Removes all key-value pairs from the map that satisfy the predicate where without notifying listeners.
silentRemoveWhere(bool where(T)) → void

Available on VN<Set<T>>, provided by the BetterSetNotifications extension

Removes all elements from the set that satisfy the predicate where without notifying listeners.
silentSet(T newValue) → void
Updates the value without notifying listeners.
smartAdd(T value) → void

Available on VN<List<T>>, provided by the BetterListNotifications extension

Adds the given value to the list, with behavior determined by ChangeType.
smartAdd(T value) bool

Available on VN<Set<T>>, provided by the BetterSetNotifications extension

Adds the given value to the set and notifies listeners if the value was added.
smartAddAll(Iterable<T> value) → void

Available on VN<List<T>>, provided by the BetterListNotifications extension

Appends all elements from the given iterable value to the list, with behavior determined by ChangeType.
smartAddAll(Iterable<T> values) → void

Available on VN<Set<T>>, provided by the BetterSetNotifications extension

Adds all elements from the given values to the set and notifies listeners if the set changed.
smartClear() → void

Available on VN<Map<K, V>>, provided by the BetterMapNotifications extension

Removes all key-value pairs from the map, with behavior determined by ChangeType.
smartClear() → void

Available on VN<Set<T>>, provided by the BetterSetNotifications extension

Removes all elements from the set and notifies listeners if the set was not empty.
smartRemove(Object? value) bool

Available on VN<List<T>>, provided by the BetterListNotifications extension

Removes the first occurrence of the given value from the list, with behavior determined by ChangeType.
smartRemove(K key) → V?

Available on VN<Map<K, V>>, provided by the BetterMapNotifications extension

Removes the key-value pair with the given key from the map, with behavior determined by ChangeType.
smartRemove(Object? value) bool

Available on VN<Set<T>>, provided by the BetterSetNotifications extension

Removes the given value from the set and notifies listeners if the set changed.
smartRemoveAt(int index) → T

Available on VN<List<T>>, provided by the BetterListNotifications extension

Removes the element at the specified index from the list, with behavior determined by ChangeType.
smartRemoveWhere(bool where(T)) → void

Available on VN<List<T>>, provided by the BetterListNotifications extension

Removes all elements that satisfy the given predicate where, with behavior determined by ChangeType.
smartRemoveWhere(bool where(T)) → void

Available on VN<Set<T>>, provided by the BetterSetNotifications extension

Removes all elements from the set that satisfy the predicate where, with behavior determined by ChangeType.
smartRemoveWhere(bool where(K key, V value)) → void

Available on VN<Map<K, V>>, provided by the BetterMapNotifications extension

Removes all key-value pairs from the map that satisfy the predicate where, with behavior determined by ChangeType.
smartSet(T newValue) → void
Updates the value if it differs from the current value, and notifies listeners.
toList() List<T>

Available on VN<Iterable<T>>, provided by the BetterIterableNotifications extension

Returns a new list containing all elements of the iterable.
toString() String
Returns a string representation of this VN.
override
where(bool function(T function)) Iterable<T>

Available on VN<Set<T>>, provided by the BetterSetNotifications extension

Returns a new lazy Iterable with all elements that satisfy the predicate function.
where(bool function(T)) Iterable<T>

Available on VN<Iterable<T>>, provided by the BetterIterableNotifications extension

Returns a new lazy Iterable with all elements that satisfy the predicate function.

Operators

operator ==(Object other) bool
The equality operator.
inherited
operator [](int index) → T

Available on VN<Iterable<T>>, provided by the BetterIterableNotifications extension

Gets the element at the specified index in the iterable.
operator [](int index) → T

Available on VN<List<T>>, provided by the BetterListNotifications extension

Gets the element at the specified index in the list.
operator [](K key) → V?

Available on VN<Map<K, V>>, provided by the BetterMapNotifications extension

Retrieves the value associated with the given key in the map.
operator [](int index) → T

Available on VN<Set<T>>, provided by the BetterSetNotifications extension

Retrieves the element at the specified index in the set.
operator []=(int index, T value) → void

Available on VN<List<T>>, provided by the BetterListNotifications extension

Sets the element at the specified index in the list to the given value.
operator []=(K key, V value) → void

Available on VN<Map<K, V>>, provided by the BetterMapNotifications extension

Associates the given key with the given value in the map.

Static Methods

merged<T, L, R>(T initialValue, {required VN<L> left, required VN<R> right, required void listener(L left, R right, void emitter(T value)), ChangeType? changeType, void whenDispose()?}) VN<T>
Factory method for creating a merged VN.