collection_notifiers library

Collection classes with ChangeNotifier and ValueListenable support.

This library provides reactive collection wrappers that notify listeners when their contents change, enabling efficient UI rebuilds in Flutter.

Available Notifiers

Usage with ValueListenableBuilder

final items = ListNotifier<String>(['a', 'b', 'c']);

ValueListenableBuilder<List<String>>(
  valueListenable: items,
  builder: (context, value, child) {
    return ListView.builder(
      itemCount: value.length,
      itemBuilder: (context, index) => Text(value[index]),
    );
  },
);

// Mutations automatically trigger rebuilds
items.add('d');

Notification Behavior

Methods only call ChangeNotifier.notifyListeners when the collection actually changes. For example:

  • set.add(existingElement) - No notification (element already exists)
  • map['key'] = sameValue - No notification (value unchanged)
  • list.clear() on empty list - No notification (nothing to clear)

This optimization prevents unnecessary widget rebuilds.

Classes

ListNotifier<E>
A List implementation that notifies listeners when modified.
MapNotifier<K, V>
A Map implementation that notifies listeners when modified.
QueueNotifier<E>
A Queue implementation that notifies listeners when modified.
SetNotifier<E>
A Set implementation that notifies listeners when modified.