I found the following description in Riverpod's documentation.
the state of a provider is not global
I believe that the state is referenced by several screens and the value is shared. (Like if you increment the counter on screen 1, the State is also incremented on screen 2...) However, the above document says that it is not shared with the Provider's Studio.
I think there is a contradiction between the two. Why is this?
CodePudding user response:
Maybe this only applies to tests. From doc:
As you can see, while counterProvider was declared as a global, no state was shared between tests. As such, we do not have to worry about our tests potentially behaving differently if executed in a different order, since they are running in complete isolation.
CodePudding user response:
Any reference via a WidgetRef
or Ref
under the same ProviderScope
or ProviderContainer
to the same Provider
(or subclass) will be referencing the same provider instance. If you think about it, it must be this way, or a provider could never be shared between widgets!