riverpod icon indicating copy to clipboard operation
riverpod copied to clipboard

Decision graph for providers

Open vigneshksaithal opened this issue 2 years ago • 2 comments

Describe what scenario you think is uncovered by the existing examples/articles I am a beginner to flutter so, I find it difficult to know which provider to use. It will be greatly helpful if there was a decision graph(like how Riverpod currently has for reading providers).

Describe why existing examples/articles do not cover this case There is a confusion between which provider to use so a decision graph will be very helpful (atleast for beginners like me).

Additional context None.

vigneshksaithal avatar Jul 18 '21 12:07 vigneshksaithal

The names of the providers generally speak for themselves:

Watch a stream: StreamProvider Watch a future: FutureProvider Watch a StateNotifier: StateNotifierProvider Watch a value design to change one or many times during the view is displayed: StateProvider Watch a provider which will not change or only change by watching other providers: Provider

A StateNotifier can generally be considered as a ViewModel: it manages a state and also handles some functions inside it.

Also, you can have a look to the source code of these two official examples:

They cover most of the available providers so you can quickly understand when to use each one.

julienlebren avatar Jul 18 '21 14:07 julienlebren

Watch a value design to change one or many times during the view is displayed: StateProvider

Could you elaborate this? I'm also looking for more docs as I'm using Riverpod since about 6 months.

ghost avatar Oct 15 '21 23:10 ghost

You don't "pick a provider"

You write your business logic normally. And based on what you wrote (a notifier, a future, ...), then the provider naturally picks itself.

In any case, codegen is here to remove this problem. So closing :)

rrousselGit avatar Oct 10 '23 17:10 rrousselGit