Is there a way to make a ChangeNotifier
listen to another ChangeNotifier
in a flutter app?
something like this:
class FirstCounter extends ChangeNotifier {
int _i = 0;
void increment() {
i = i + 1;
notifyListeners();
}
}
class SecoundCounter extends ChangeNotifier {
int _i = 0;
void increment() {
i = i + 1;
notifyListeners();
}
void listen() {
var resetCallback = () { i = 0;}
FirstCounter.listen(resetCallback);
}
}
I want SecoundCounter
to reset when FirstCounter
is updated.
2
Answers
use
first.addListener(second.reset);