Recently I discovered that we can access the provider value using either
Consumer<Model>(build: (context, value, child){
return Widget(child: value.valueName),
},
)
Or using
context.watch<Model>().valueName
What is the best practice?
Recently I discovered that we can access the provider value using either
Consumer<Model>(build: (context, value, child){
return Widget(child: value.valueName),
},
)
Or using
context.watch<Model>().valueName
What is the best practice?
They are the same. it depends on your needs.
context.watch<T>()
and Consumer<T>
does the same thing. Most of the time context.watch<T>()
is just more convenient. In some cases where context is not available Consumer is useful.
if you want to find an answer that explained how to use provider you can use my answer.
happy coding...