r/FlutterDev • • Oct 07 '22

Article Flutter Riverpod 2.0: The Ultimate Guide

https://codewithandrea.com/articles/flutter-state-management-riverpod/
206 Upvotes

21 comments sorted by

53

u/bizz84 Oct 07 '22

I just published an extensive and up to date guide to Riverpod 2.0.

This is way too long to share a summary, so here's the table of contents:

  • Why use Riverpod?

  • Riverpod Installation

    • ProviderScope

  • What is a Riverpod Provider?

  • Creating and Reading a Provider

    • Using a ConsumerWidget

    • Using a Consumer

    • Using ConsumerStatefulWidget & ConsumerState

  • What is a WidgetRef?

  • Six different kinds of providers

    • Provider

    • StateProvider

    • StateNotifierProvider

    • FutureProvider

    • StreamProvider

    • ChangeNotifierProvider

  • When to use ref.watch vs ref.read?

    • Listening to Provider State Changes

  • Additional Riverpod Features

  • The autoDispose modifier

    • Caching with Timeout

  • The family modifier

  • Dependency Overrides with Riverpod

  • Combining Providers with Riverpod

    • Passing Ref as an argument

  • Scoping Providers

  • Filtering widget rebuilds with "select"

  • Testing with Riverpod

    • How to mock and override dependencies in tests

  • Logging with ProviderObserver

  • Quick Note about App Architecture with Riverpod

Hope you find it useful!

Happy coding!

5

u/CodyLeet Oct 07 '22

Why is this called RiverPod?

16

u/bizz84 Oct 07 '22

Itโ€™s an anagram of Provider.

9

u/remirousselet Oct 08 '22

And "River" because it fits in the water theme of "Streams"

3

u/logickoder Oct 08 '22

Wow, never really saw this until now ๐Ÿ˜‚

6

u/J3b3 Oct 07 '22

Very nice (as usual ๐Ÿ˜Ž), thanks! ๐Ÿ‘Œ

6

u/Flashy_Editor6877 Oct 07 '22

nice article thx. may have to try it, seems to be a replacement for get_it? i use bloc so this might be overkill. thoughts?

also, rp2 consumers remind me of getx. you gotta admit and give credit of the power and simplicity of the magic "global variable" getx pioneered. i agree with all other problems of getx though.

1

u/plusema Oct 07 '22

Iโ€™m also curious to know if with riverpod 2.0 we will no longer need get_it

2

u/GetBoolean Oct 08 '22

Riverpod does DI, but you don't have to use it for that

1

u/Acrobatic_Egg30 Oct 10 '22

I'm sorry but this guide is not as complete as you say, it doesn't talk about the new @riverpod stuff, codegen and the new build method.

1

u/bizz84 Oct 13 '22

As I have said in the guide, I'll cover the Riverpod Generator in a separate article (coming soon!).

1

u/Acrobatic_Egg30 Oct 13 '22

I must've missed that. I read your articles religiously so I was a bit disappointed to not see explanations on the new stuff in riverpod. Felt a bit click-baity

2

u/bizz84 Oct 13 '22

Thereโ€™s so much to cover that itโ€™s worth splitting it into separate articles. The new generator is optional so it makes sense to cover it separately.

3

u/BewbyBewbs Oct 10 '22

Man I just don't understand riverpod. The examples everywhere are extremely simple.

2

u/pattobrien Oct 07 '22

Thanks so much Andrea! Looking forward to your riverpod_generator article too.

1

u/Flashy_Editor6877 Oct 08 '22

this is such a good guide, it's making me consider adding riverpod to my toolkit. i wish there was one like this for bloc ๐Ÿ˜‰ any plans for that?

also, is rp2 fully production ready?

-10

u/Benatar111 Oct 07 '22 edited Oct 07 '22

aight got it will ask in the relevant palces

0

u/[deleted] Oct 07 '22

[deleted]

3

u/Kloth494 Oct 08 '22

I haven't used Riverpod by myself yet, but if Provider satisfies your needs there is no need to switch. Don't hop on the wagon because it is "standard".

1

u/Akimotoh Oct 07 '22

I would also like to know the answer to this!

u/remirousselet does this guide pass your bar of quality? :)