SetSignal<E> class
A reactive Signal that holds a Set and implements the Set interface.
SetSignal lets you listen to changes on a set reactively and mutate it directly using
standard set operations (like add, addAll, remove, clear, etc.). Any mutations
automatically trigger reactive updates to all active listeners (e.g., inside an effect
or computed).
Additionally, SetSignal defines convenient operators:
<<injects/adds all items from another set into the current set.&forks/unions the set with another set into a new SetSignal.|pipes/unions the set with another signal holding an iterable into a new SetSignal.
Example Usage
import 'package:signals/signals.dart';
void main() {
final numbers = setSignal<int>({1, 2, 3});
effect(() {
print('Set content: $numbers, Length: ${numbers.length}');
}); // Prints: "Set content: {1, 2, 3}, Length: 3"
// Standard mutation (triggers updates)
numbers.add(4); // Prints: "Set content: {1, 2, 3, 4}, Length: 4"
// Removing an element (triggers updates)
numbers.remove(1); // Prints: "Set content: {2, 3, 4}, Length: 3"
// Set intersection (reactive query)
final common = numbers.intersection({3, 4, 5});
print(common); // Prints: {3, 4}
}
:::tip
Mutating the collection directly calls the reactive set() routine under the hood automatically. You
do not need to assign numbers.value = ... manually!
:::
- Inheritance
- Implemented types
-
- Set<
E>
- Set<
- Mixed-in types
-
- IterableSignalMixin<
E, Set< E> > - SetSignalMixin<
E, Set< E> >
- IterableSignalMixin<
- Available extensions
Constructors
-
SetSignal(Set<
E> value, {SetSignalOptions<E> ? options, @Deprecated('Use options: SetSignalOptions(autoDispose: ...) instead') bool? autoDispose, @Deprecated('Use options: SetSignalOptions(name: ...) instead') String? debugLabel}) -
Creates a SetSignal with the given
value.
Properties
-
$
→ Signal<
Iterable< E> > -
Available on Iterable<
Return a signal from a Iterable valueE> , provided by the SignalIterableExtensions extensionno setter -
$
→ Signal<
Set< E> > -
Available on Set<
Lift a primitive Set into a reactive Signal<Set<E>>.E> , provided by the SignalSetExtensions extensionno setter - autoDispose ↔ bool
-
Throws and error if read after dispose and can be
disposed on last unsubscribe.
getter/setter pairinherited
- debugLabel → String?
-
Debug label for Debug Mode
Debug label for Debug Mode
no setterinherited
- disposed ↔ bool
-
Check if the effect is disposed
getter/setter pairinherited
-
equalityCheck
→ SignalEquality<
Set< E> > -
Optional method to check if to values are the same
no setterinherited
- first → E
-
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 - globalId → int
-
finalinherited
- hashCode → int
-
The hash code for this object.
no setteroverride
-
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 -
internalValue
→ Set<
E> -
@internal
Internal getter for the raw value without subscription tracking.
no setterinherited
- isEmpty → bool
-
Whether this collection has no elements.
no setterinherited
- isInitialized → bool
-
Check if a signal value is set (does not subscribe)
no setterinherited
- isNotEmpty → bool
-
Whether this collection has at least one element.
no setterinherited
-
iterator
→ Iterator<
E> -
A new
Iteratorthat allows iterating the elements of thisIterable.no setterinherited - last → E
-
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
- name → String?
-
finalinherited
-
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 → E
-
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 -
toJSIterable
→ JSIterable<
T> -
Available on Iterable<
A JSIterable wrapper that proxies to the Dart iterable API.T> , provided by the IterableToJSIterable extensionno setter - unwatched → void Function()?
-
finalinherited
-
value
↔ Set<
E> -
Gets the current value of the signal.
getter/setter pairinherited
- version ↔ int
-
Version numbers should always be >= 0, because the special value -1 is used
by Nodes to signify potentially unused but recyclable nodes.
getter/setter pairinherited
-
wait
→ Future<
List< T> > -
Available on Iterable<
Waits for futures in parallel.Future< , provided by the FutureIterable extensionT> >no setter - watched → void Function()?
-
finalinherited
Methods
-
add(
E value) → bool -
Available on Signal<
Set< , provided by the SetSignalExtension extensionE> > -
add(
E value) → bool -
Adds
valueto the set.inherited -
addAll(
Iterable< E> elements) → void -
Available on Signal<
Set< , provided by the SetSignalExtension extensionE> > -
addAll(
Iterable< E> elements) → void -
Adds all
elementsto this set.inherited -
any(
bool test(E element)) → 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. -
call(
) → Set< E> -
Return the value when invoked
inherited
-
cast<
R> () → Set< R> -
Provides a view of this set as a set of
Rinstances.inherited -
cast<
R> () → Set< R> -
Available on ReadonlySignal<
Set< , provided by the ReadonlySetSignalExtension extensionE> > -
clear(
) → void -
Available on Signal<
Set< , provided by the SetSignalExtension extensionE> > -
clear(
) → void -
Removes all elements from the set.
inherited
-
contains(
Object? value) → 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 -
containsAll(
Iterable< Object?> other) → bool -
Available on ReadonlySignal<
Set< , provided by the ReadonlySetSignalExtension extensionE> > -
difference(
Set< Object?> other) → Set<E> -
Available on ReadonlySignal<
Set< , provided by the ReadonlySetSignalExtension extensionE> > -
difference(
Set< Object?> other) → Set<E> -
Creates a new set with the elements of this that are not in
other.inherited -
dispose(
) → void -
Dispose the signal
inherited
-
elementAt(
int index) → E -
Returns the
indexth element.inherited -
elementAtOrNull(
int index) → T? -
Available on Iterable<
The element at positionT> , provided by the IterableExtensions extensionindexof this iterable, ornull. -
every(
bool test(E element)) → bool -
Checks whether every element of this iterable satisfies
test.inherited -
expand<
R> (Iterable< R> toElements(E element)) → Iterable<R> -
Expands each element of this Iterable into zero or more elements.
inherited
-
firstWhere(
bool test(E element), {E orElse()?}) → E -
The first element that satisfies the given predicate
test.inherited -
fold<
R> (R initialValue, R combine(R previousValue, E element)) → R -
Reduces a collection to a single value by iteratively combining each
element of the collection with an existing value
inherited
-
followedBy(
Iterable< E> other) → Iterable<E> -
Creates the lazy concatenation of this iterable and
other.inherited -
forEach(
void action(E element)) → void -
Invokes
actionon each element of this iterable in iteration order.inherited -
get(
) → Set< E> -
Helper method to get the current value
inherited
-
internalRefresh(
) → bool -
@internal
Refreshes the signal's value internally.
inherited
-
intersection(
Set< Object?> other) → Set<E> -
Available on ReadonlySignal<
Set< , provided by the ReadonlySetSignalExtension extensionE> > -
intersection(
Set< Object?> other) → Set<E> -
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(E element), {E orElse()?}) → E -
The last element that satisfies the given predicate
test.inherited -
lookup(
Object? object) → E? -
Available on ReadonlySignal<
Set< , provided by the ReadonlySetSignalExtension extensionE> > -
lookup(
Object? object) → E? -
If an object equal to
objectis in the set, return it.inherited -
map<
R> (R toElement(E e)) → Iterable< R> -
The current elements of this iterable modified by
toElement.inherited -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
onDispose(
void cleanup()) → void Function() -
Add a cleanup function to be called when the signal is disposed
inherited
-
overrideWith(
Set< E> val) → Signal<Set< E> > -
Override the current signal with a new value as if it was created with it.
inherited
-
peek(
) → Set< E> -
In the rare instance that you have an effect that should write to another signal based on the previous value, but you don't want the effect to be subscribed to that signal, you can read a signals's previous value via
signal.peek().inherited -
readonly(
) → ReadonlySignal< Set< E> > -
Returns a readonly signal
inherited
-
reduce(
E combine(E value, E element)) → E -
Reduces a collection to a single value by iteratively combining elements
of the collection using the provided function.
inherited
-
remove(
Object? value) → bool -
Available on Signal<
Set< , provided by the SetSignalExtension extensionE> > -
remove(
Object? value) → bool -
Removes
valuefrom the set.inherited -
removeAll(
Iterable< Object?> elements) → void -
Removes each element of
elementsfrom this set.inherited -
removeAll(
Iterable< Object?> elements) → void -
Available on Signal<
Set< , provided by the SetSignalExtension extensionE> > -
removeWhere(
bool test(E element)) → void -
Removes all elements of this set that satisfy
test.inherited -
removeWhere(
bool test(E element)) → void -
Available on Signal<
Set< , provided by the SetSignalExtension extensionE> > -
retainAll(
Iterable< Object?> elements) → void -
Removes all elements of this set that are not elements in
elements.inherited -
retainAll(
Iterable< Object?> elements) → void -
Available on Signal<
Set< , provided by the SetSignalExtension extensionE> > -
retainWhere(
bool test(E element)) → void -
Removes all elements of this set that fail to satisfy
test.inherited -
retainWhere(
bool test(E element)) → void -
Available on Signal<
Set< , provided by the SetSignalExtension extensionE> > -
set(
Set< E> val, {bool force = false}) → bool -
Updates the signal's value by method call.
inherited
-
singleWhere(
bool test(E element), {E orElse()?}) → E -
The single element that satisfies
test.inherited -
skip(
int count) → Iterable< E> -
Creates an Iterable that provides all but the first
countelements.inherited -
skipWhile(
bool test(E value)) → Iterable< E> -
Creates an
Iterablethat skips leading elements whiletestis satisfied.inherited -
subscribe(
void fn(Set< E> value)) → void Function() -
Subscribe to value changes with a dispose function
inherited
-
subscribeToNode(
Node node) → void -
@internal
Subscribes this signal to notifications from a given dependency
node.inherited -
take(
int count) → Iterable< E> -
Creates a lazy iterable of the
countfirst elements of this iterable.inherited -
takeWhile(
bool test(E value)) → Iterable< E> -
Creates a lazy iterable of the leading elements satisfying
test.inherited -
toJson(
) → dynamic -
Convert value to JSON
inherited
-
toList(
{bool growable = true}) → List< E> -
Creates a List containing the elements of this Iterable.
inherited
-
toSet(
) → Set< E> -
Creates a Set containing the same elements as this iterable.
inherited
-
toSignal(
{SetSignalOptions< T> ? options, bool? autoDispose, String? debugLabel}) → SetSignal<T> -
Available on Set<
Convert this existing Set to a reactive SetSignal.T> , provided by the SignalSetUtils extension -
toSignal(
{IterableSignalOptions< T> ? options, bool? autoDispose, String? debugLabel}) → IterableSignal<T> -
Available on Iterable<
Convert an existing Iterable to an IterableSignal.T> , provided by the SignalIterableUtils extension -
toString(
) → String -
A string representation of this object.
inherited
-
union(
Set< E> other) → Set<E> -
Creates a new set which contains all the elements of this set and
other.inherited -
union(
Set< E> other) → Set<E> -
Available on ReadonlySignal<
Set< , provided by the ReadonlySetSignalExtension extensionE> > -
unsubscribeFromNode(
Node node) → void -
@internal
Unsubscribes this signal from notifications from a given dependency
node.inherited -
where(
bool test(E element)) → Iterable< E> -
Creates a new lazy Iterable with all elements that satisfy the
predicate
test.inherited -
whereType<
R> () → Iterable< R> -
Creates a new lazy Iterable with all elements that have type
T.inherited
Operators
-
operator &(
Set< E> other) → SetSignal<E> - Fork: create a new signal with value is the concatenation of source signal and iterable parameter
-
operator <<(
Set< E> other) → SetSignal<E> - Inject: Update current signal value with iterable
-
operator ==(
Object other) → bool -
The equality operator.
override
-
operator |(
Signal< Iterable< other) → SetSignal<E> >E> - Pipe: create a new signal by sending value from source to other