Theoretically, if the class of the object is a ChangeNotifier/Listenable, I can see how that would be possible. But if the class is a plain Dart class, how does Provider.of<>(context) listen to updates and rebuilds the widget when the object changes?
Asked
Active
Viewed 579 times
0
-
When we use `notifyListner()` it updates the value – Md. Yeasin Sheikh Feb 12 '22 at 09:51
-
https://stackoverflow.com/a/68418866/16467763 Use provider like this. Try this way. – DholaHardik Feb 12 '22 at 09:59
1 Answers
0
Just to clarify, when you use ChangeNotifier/Listenable and update your values, your values actually updates, now the problem is how do you let your widget know there's an updated value for rebuild, that's what provider tries to solve by letting your use Provider.of(context, listen:true)
to listen for changes in values and when this happens your initial value or widget holding that value is destroyed and a new one is created for you with the updated values, likewise ConsumerWidget helps you achieve the same thing by rebuilding the children holding values with the updated value.
PS: you have to inform your providers or consumers about the updated values with notifylisteners()
for them to rebuild when there's a change in values.

odinachi
- 180
- 1
- 5