I’m using Provider in my app and my ask/issues is:
I have 2 Pages which use a provider. In this Provider has a variable String which show in one page but the another Page change the value of this variable. So, when change the value of variable my Page Update all Widget (From scaffold) instead of widget which use the variable
I use the provider with provider.of before the Return of the build
2
Answers
you can use Consumer/Selector, Their optional child argument allows rebuilding only a particular part of the widget tree:
Provider.of
also has another parameter calledlisten
.Its default value is true.If listen is true, then when the value of provider changes, the state will be rebuilt. You can use
listen: false
to get the Provider and wrap the widget you want to update withSelector
orConsumer
.Provider has added extensions to BuildContext, allowing you to use
watch
orread
for a more intuitive way of accessing Provider.