Equivalent of Provider.value in Riverpod Flutter

Viewed 310

I have been trying to migrate my old projects from provider to riverpod. What is the equivalent of using Provider.value in riverpod? What I am trying to do is, after authentication, I want to be able to access User from all places thus I am passing User down the widget tree using Provider.value like this:

Provider<AuthUser>.value(value: user);
2 Answers

The primary advantage of Riverpod is that its not attached to the widget tree so there is no need to use .value , if the provider already exists in another route, it will use it, for a better example you would need to upload some code about what you're trying to code for a more specific answer

I have a similar use case. What you could do is have a StateProvider and once the user is logged in, you update the state of this provider with user data. From now on other providers and widgets can get the user by getting the state of this provider using e.g. watch.

Related