Home > database >  If another variable in ChangeNotifier is changed, will the Consumer's model be updated?
If another variable in ChangeNotifier is changed, will the Consumer's model be updated?

Time:10-25

If the following setIntVal is called and notifyListeners(); is executed, is the Text redrawn? intVal is changed but strVal is not.

Similarly, what happens when StateNotifier is used?

class DummyManager with ChangeNotifier {
  DummyManager();

  int intVal = 0;
  String strVal = "";

  void setIntVal(val) {
    intVal = val;
    notifyListeners();
  }
}

Consumer<DummyManager>(
    builder: (context, model, child) {
      return Text(model.strVal);
    },
)

CodePudding user response:

yes of course redrawn, and notify all listeners and by the end consumer have a listener to do this

CodePudding user response:

You modify your state object in your StateNotifier class and the interface is redrawn. Just have to consider that the new state must be a new object and immutable

  • Related