SetNotifier<T> class
A Set that behaves like ValueNotifier if its data changes.
Notification Modes
-
CustomNotifierMode.normal: Listeners are only notified when a value actually changes. For example, adding an element that already exists in the set will not notify listeners. No-op operations (like removing a non-existent element) also won't notify.
-
CustomNotifierMode.always: Listeners are notified on every operation, even if the set doesn't change. This ensures UI always updates when operations are attempted.
-
CustomNotifierMode.manual: No automatic notifications. You must call notifyListeners manually after making changes.
Bulk Operations
Bulk operations like addAll, removeAll, and retainAll always notify
listeners, even with empty input, regardless of notification mode (except
manual). This ensures consistent behavior and prevents subtle bugs.
Transactions
Use startTransAction and endTransAction to batch multiple operations into a single notification. This is useful for atomic updates.
Set Operations
Set operations like union(), intersection(), and difference() return
new sets and don't modify the current set, so they don't trigger
notifications and are not overridden.
Note on Equality
Unlike ListNotifier and MapNotifier, SetNotifier does NOT support
custom equality functions. Sets inherently use == and hashCode for
membership testing, and custom equality would only apply to notification
decisions, which could be confusing. Use the built-in equality behavior.
Examples
// Normal mode - only notifies on actual changes
final setNotifier = SetNotifier<int>(
data: {1, 2, 3},
notificationMode: CustomNotifierMode.normal,
);
setNotifier.add(1); // No notification (already exists)
setNotifier.add(4); // Notifies (new element added)
setNotifier.remove(99); // No notification (doesn't exist)
// Always mode - notifies on every operation
final alwaysSet = SetNotifier<int>(
data: {1, 2, 3},
notificationMode: CustomNotifierMode.always,
);
alwaysSet.add(1); // Notifies even though element exists
- Implemented types
-
- ValueListenable<
Set< T> > - Set<
E> - Iterable<
E>
- ValueListenable<
- Mixed-in types
- Available extensions
Constructors
-
SetNotifier({Set<
T> ? data, CustomNotifierMode notificationMode = CustomNotifierMode.always}) - Creates a new listenable Set.
Properties
- first → T
-
The first element.
no setterinherited
- firstOrNull → T?
-
Available on Iterable<
The first element of this iterator, orT> , provided by the IterableExtensions extensionnullif the iterable is empty.no setter - hashCode → int
-
The hash code for this object.
no setterinherited
- hasListeners → bool
-
Whether any listeners are currently registered.
no setterinherited
-
indexed
→ Iterable<
(int, T)> -
Available on Iterable<
Pairs of elements of the indices and elements of this iterable.T> , provided by the IterableExtensions extensionno setter - isEmpty → bool
-
Whether this collection has no elements.
no setterinherited
- isNotEmpty → bool
-
Whether this collection has at least one element.
no setterinherited
-
iterator
→ Iterator<
T> -
A new
Iteratorthat allows iterating the elements of thisIterable.no setterinherited - last → T
-
The last element.
no setterinherited
- lastOrNull → T?
-
Available on Iterable<
The last element of this iterable, orT> , provided by the IterableExtensions extensionnullif the iterable is empty.no setter - length → int
-
The number of elements in this Iterable.
no setterinherited
-
nonNulls
→ Iterable<
T> -
Available on Iterable<
The non-T?> , provided by the NullableIterableExtensions extensionnullelements of this iterable.no setter - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- single → T
-
Checks that this iterable has only one element, and returns that element.
no setterinherited
- singleOrNull → T?
-
Available on Iterable<
The single element of this iterator, orT> , provided by the IterableExtensions extensionnull.no setter -
value
→ Set<
T> -
Returns an immutable view of the current set state.
no setteroverride
-
wait
→ Future<
List< T> > -
Available on Iterable<
Waits for futures in parallel.Future< , provided by the FutureIterable extensionT> >no setter
Methods
-
add(
T value) → bool -
from here all functions are equal to
Set<T>with the addition that all modifying functions will callnotifyListenerif not in a transaction. -
addAll(
Iterable< T> elements) → void -
Adds all
elementsto this set. -
addListener(
VoidCallback listener) → void -
Register a closure to be called when the object changes.
inherited
-
any(
bool test(T)) → bool -
Checks whether any element of this iterable satisfies
test.inherited -
asNameMap(
) → Map< String, T> -
Available on Iterable<
Creates a map from the names of enum values to the values.T> , provided by the EnumByName extension -
byName(
String name) → T -
Available on Iterable<
Finds the enum value in this list with nameT> , provided by the EnumByName extensionname. -
cast<
T> () → Set< T> -
A view of this iterable as an iterable of
Rinstances.inherited -
clear(
) → void - Removes all elements from the set.
-
contains(
Object? element) → bool -
Whether the collection contains an element equal to
element.inherited -
containsAll(
Iterable< Object?> other) → bool -
Whether this set contains all the elements of
other.inherited -
debounce(
Duration timeOut) → Listenable -
Available on Listenable, provided by the FunctionaListener2 extension
-
difference(
Set< Object?> other) → Set<T> -
Creates a new set with the elements of this that are not in
other.inherited -
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
-
elementAt(
int index) → T -
Returns the
indexth element.inherited -
elementAtOrNull(
int index) → T? -
Available on Iterable<
The element at positionT> , provided by the IterableExtensions extensionindexof this iterable, ornull. -
endTransAction(
) → void - Ends a transaction.
-
every(
bool test(T)) → bool -
Checks whether every element of this iterable satisfies
test.inherited -
expand<
T> (Iterable< T> f(T)) → Iterable<T> -
Expands each element of this Iterable into zero or more elements.
inherited
-
firstWhere(
bool test(T), {T orElse()?}) → T -
The first element that satisfies the given predicate
test.inherited -
fold<
T> (T initialValue, T combine(T previousValue, T element)) → T -
Reduces a collection to a single value by iteratively combining each
element of the collection with an existing value
inherited
-
followedBy(
Iterable< T> other) → Iterable<T> -
Creates the lazy concatenation of this iterable and
other.inherited -
forEach(
void f(T)) → void -
Invokes
actionon each element of this iterable in iteration order.inherited -
intersection(
Set< Object?> other) → Set<T> -
Creates a new set which is the intersection between this set and
other.inherited -
join(
[String separator = '']) → String -
Converts each element to a String and concatenates the strings.
inherited
-
lastWhere(
bool test(T), {T orElse()?}) → T -
The last element that satisfies the given predicate
test.inherited -
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. -
lookup(
Object? element) → T? -
If an object equal to
objectis in the set, return it.inherited -
map<
T> (T f(T)) → Iterable< T> -
The current elements of this iterable modified by
toElement.inherited -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
notifyListeners(
) → void -
If needed you can notify all listeners manually.
override
-
reduce(
T combine(T value, T element)) → T -
Reduces a collection to a single value by iteratively combining elements
of the collection using the provided function.
inherited
-
remove(
Object? value) → bool -
Removes
valuefrom the set. -
removeAll(
Iterable< Object?> elements) → void -
Removes each element of
elementsfrom this 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 test(T)) → void -
Removes all elements of this set that satisfy
test. -
retainAll(
Iterable< Object?> elements) → void -
Removes all elements of this set that are not elements in
elements. -
retainWhere(
bool test(T)) → void -
Removes all elements of this set that fail to satisfy
test. -
retype<
T> () → Set< T> -
inherited
-
singleWhere(
bool test(T), {T orElse()?}) → T -
The single element that satisfies
test.inherited -
skip(
int n) → Iterable< T> -
Creates an Iterable that provides all but the first
countelements.inherited -
skipWhile(
bool test(T)) → Iterable< T> -
Creates an
Iterablethat skips leading elements whiletestis satisfied.inherited -
startTransAction(
) → void - Starts a transaction that allows to make multiple changes to the Set with only one notification at the end.
-
take(
int n) → Iterable< T> -
Creates a lazy iterable of the
countfirst elements of this iterable.inherited -
takeWhile(
bool test(T)) → Iterable< T> -
Creates a lazy iterable of the leading elements satisfying
test.inherited -
toList(
{bool growable = true}) → List< T> -
Creates a List containing the elements of this Iterable.
inherited
-
toSet(
) → Set< T> -
Creates a Set containing the same elements as this iterable.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
union(
Set< T> other) → Set<T> -
Creates a new set which contains all the elements of this set and
other.inherited -
where(
bool test(T)) → Iterable< T> -
Creates a new lazy Iterable with all elements that satisfy the
predicate
test.inherited -
whereType<
T> () → Iterable< T> -
Creates a new lazy Iterable with all elements that have type
T.inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited