Skip to content

Instantly share code, notes, and snippets.

@TesteurManiak
Created February 27, 2024 15:30
Show Gist options
  • Select an option

  • Save TesteurManiak/51d0663c4a1d5071cddd77658cabcf0a to your computer and use it in GitHub Desktop.

Select an option

Save TesteurManiak/51d0663c4a1d5071cddd77658cabcf0a to your computer and use it in GitHub Desktop.
A ChangeNotifier that listens to multiple Listenables.
/// A [ChangeNotifier] that listens to multiple [Listenable]s.
class RefreshNotifier extends ChangeNotifier {
RefreshNotifier(this._listenables) {
for (final listenable in _listenables) {
listenable.addListener(notifyListeners);
}
}
final List<Listenable> _listenables;
@override
void dispose() {
for (final listenable in _listenables) {
listenable.removeListener(notifyListeners);
if (listenable is ChangeNotifier) listenable.dispose();
}
super.dispose();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment