reactive property

Reactive<Set<E>> get reactive

Creates a reactive set from this set.

The returned Reactive instance will contain a copy of the original set, so modifications to the original set won't affect the reactive set.

Example:

final tags = {'dart', 'flutter', 'reactive'}.reactive;
print(tags.value); // {dart, flutter, reactive}

// Update the reactive set
tags.value.add('state');
tags.value = Set.from(tags.value); // Trigger notification
print(tags.value); // {dart, flutter, reactive, state}

// Adding a duplicate has no effect (sets only contain unique elements)
tags.value.add('dart');
print(tags.value); // {dart, flutter, reactive, state}

Note: When you modify a reactive set's elements, you need to reassign the set to trigger a notification, since sets are mutable objects.

Implementation

Reactive<Set<E>> get reactive {
  return Reactive<Set<E>>(Set<E>.from(this));
}