A mixin that adds reactive Map methods and operators directly to a Signal.
This mixin delegates all standard Map operations (such as mutations like []=,
clear,
remove, and lookups like containsKey, isEmpty,
keys, values) to the underlying
map value.
Every mutating operation automatically updates the signal and notifies its observers
(by forcing a change notification using force: true).
Simple Example#
class MyMapSignal<K, V> extends Signal<Map<K, V>>
with MapSignalMixin<K, V, Map<K, V>> {
MyMapSignal(super.value);
}
final cart = MyMapSignal<String, int>({'apple': 1});
// Register an effect reacting to cart changes
effect(() {
print('Cart length: ${cart.length}');
});
// Treating it as a standard Map triggers updates automatically!
cart['banana'] = 3; // Prints: Cart length: 2
cart.remove('apple'); // Prints: Cart length: 1
Methods#
View Methods
V? [](Object? key)
void []=(K key, V value)
void addAll(Map<K, V> other)
void addEntries(Iterable<MapEntry<K, V>> newEntries)
Map<RK, RV> cast()
void clear()
bool containsKey(Object? key)
bool containsValue(Object? value)
Iterable<MapEntry<K, V>> entries
void forEach(void Function(K key, V value) action)
bool isEmpty
bool isNotEmpty
Iterable<K> keys
int length
Map<K2, V2> map(MapEntry<K2, V2> Function(K key, V value) convert)
V putIfAbsent(K key, V Function() ifAbsent)
V? remove(Object? key)
void removeWhere(bool Function(K key, V value) test)
V update(K key, V Function(V value) update, {V Function()? ifAbsent})
void updateAll(V Function(K key, V value) update)
Iterable<V> values
Map<K, V> toMap()
Snapshot of MapEntries