Created
February 27, 2024 15:30
-
-
Save TesteurManiak/51d0663c4a1d5071cddd77658cabcf0a to your computer and use it in GitHub Desktop.
A ChangeNotifier that listens to multiple Listenables.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /// 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