A widget builder whose content stays synced with one or more Listenable
s.
Many of us flutter developers use ChangeNotifier
for state management, they may use ListenableBuilder
to keep their widgets in sync with the model, but it's a mess when they need to listen to more than one Listenable
s.
Let's say you have a model of ChangeNotifier
like this:
class CounterModel extends ChangeNotifier {
int _count = 0;
void increment() {
_count++;
notifyListeners();
}
int get count => _count;
}
Then in the build method of your widget:
MultiListenableBuilder(
// supply the instance of `ChangeNotifier` model,
// whether you get it from the build context or anywhere
notifiers: [_counterModel],
// this builder function will be executed,
// once the `ChangeNotifier` model is updated
builder: (BuildContext context, _) {
return Text(
'${_counterModel.count}',
style: Theme.of(context).textTheme.headlineMedium,
);
},
)
Feel free to contribute to this project.
If you find a bug or want a feature, but don't know how to fix/implement it, please fill an issue. If you fixed a bug or implemented a feature, please send a pull request.