flutter-todo-list-tutorial icon indicating copy to clipboard operation
flutter-todo-list-tutorial copied to clipboard

State management with Riverpod

Open SimonLab opened this issue 4 years ago • 2 comments

Now that a first version of stage management is implement (see https://github.com/dwyl/flutter-todo-list-tutorial/issues/22) I want to look at Riverpod and understand how it works and how it can improve the application, see https://pub.dev/packages/riverpod

This project can be considered as a rewrite of provider to make improvements that would be otherwise impossible.

SimonLab avatar Feb 24 '21 16:02 SimonLab

I've started to change the code to use Riverpod (see #28). Creating Riverpod providers for the todolist itself work however I haven't managed to create providers for the items (too manage the "completed" status). I've looked at the following example: https://github.com/rrousselGit/river_pod/tree/master/examples/todos but I need to understand more Riverpod concepts to undersatnd fully the code. I'm watching the following serie: https://www.youtube.com/playlist?list=PLjr4ufdmNA4IjEQ6xIv_sQdyBhm2kn1Qv and update the code as I learn more about how to use Riverpod

SimonLab avatar May 28 '21 16:05 SimonLab

Providers: Objects that contains value that can be listen to. When the values change the providers will notify the listening widgets. Different providers exist to be able to listen to different type of values/objects

  • Provider: read only for simple value
  • StateProvider
  • StateNotifierProvider (to be used with StateNotifier values)
  • FutureProvider
  • StreamProvider
  • ProviderScope
  • ScopedProvider
  • ChangeNotifierProvider (to be used with ChangeNotifier value. StateProvider/StateNotifierProvider can be used instead of this provider)

ref:

  • https://riverpod.dev/docs/concepts/providers: A good brief on what are providers
  • https://developermemos.com/posts/different-providers-riverpod: Short explanations of the different providers
  • https://pub.dev/documentation//flutter_riverpod/latest/flutter_riverpod/flutter_riverpod-library.html : The flutter riverpod library documentation

SimonLab avatar Jun 08 '21 16:06 SimonLab

@LuchoTurtle please research and confirm if Riverpod is still the "best" way to manage state in a Flutter app in 2022 or if the Flutter core now has this functionality or there is another package that we could/should use instead. 🔍

My reading of the https://pub.dev/packages/riverpod docs is that the project is well-maintained: riverpod-web-mobile

but if there is something built-in that we can use instead, then we should consider it. 💭

Thanks! 🙏

nelsonic avatar Nov 08 '22 11:11 nelsonic

I've talked with a friend about this, as he has worked with Flutter for much more time and he highly recommended Bloc as a state management tool. In fact, it seems the community usually gravitate between Riverpod and Bloc quite often:

  • https://www.reddit.com/r/FlutterDev/comments/pjj40p/riverpod_vs_bloc/
  • https://www.reddit.com/r/FlutterDev/comments/kyd7zs/riverpod_a_better_state_management_solution_than/
  • https://www.reddit.com/r/FlutterDev/comments/wmh2oh/eli5_bloc_compared_to_providerriverpod/

and both in fact are the gold standard when it comes to state management. However, some differences do exist. Riverpod appears to be a Provider 2.0 while Bloc is an opinionated framework. Bloc forces you to separate UI and logic while Riverpod is more flexible. There are also arguments that Bloc offers more value as the project grows and Riverpod allows for faster iteration on smaller projects.

People also say Riverpod's documentation and testing are lacking, when compared with Bloc.

People say Bloc is too opinionated and rigid.

It's an endless discussion

We can compare the activity and momentum between Riverpod and Bloc by just looking at their repos https://github.com/felangel/bloc https://github.com/rrousselGit/riverpod

Bloc seems to take the cake.

Food for thought.

LuchoTurtle avatar Nov 28 '22 18:11 LuchoTurtle

@LuchoTurtle happy to trust @freitzzz experience on this one; seems to know what he's doing. 🥋 Thank you for reaching out to him for expert insight. Good to see you leveraging your network. 👌 And thanks for sharing links to discussions on Reddit. 👀

nelsonic avatar Nov 30 '22 08:11 nelsonic

https://github.com/dwyl/flutter-todo-list-tutorial/pull/28 merged. ✅

nelsonic avatar Feb 04 '23 07:02 nelsonic