3 difficulties when I switched my state management from BloC to Riverpod in Flutter
Abhinav Srivastava
Google Certified || IT Lead || Project Management || Product Management || Flutter || Flutter Lead || Flutter Mobile Apps || VOIP-SIP || Dart || Talks about #Technologies #Innovations #Entrepreneurship
Hello everyone. In this Medium article, I’m gonna talk about 3 difficulties when I switched my state management from BloC to Riverpod.
First things first, I need to say I develop applications for approximately 2 years in the Flutter section. Sometimes I write articles for applications that are useful for people who want to use already built applications like phone number sign-in or normal sign-in, maybe sometimes UI applications (e-commerce, podcast, etc.). When I developed these applications, and also for 2 years, I used BloC/Cubit state management solutions for the applications. It was a great experience for me. Recently, using Riverpod’s own documentation, I switched my state management solution. In this article, I will tell you what did my expectations, and what did I do.
1. Lots of Provider types
Actually, before the bloc, I wanted to use Providers for the state management, but I could not, since there are lots of Providers, such as Provider, FutureProvider, StreamProvider, etc. Of course, these are the basics, but before the 2 years, I had no idea about them, or in the other words, I did not know the process, I just built basics apps. When I felt to switch, there is a Riverpod, which is also a provider. My aim was to learn providers first, and after that, I wanted to switch to other sections. So, firstly, since I know the BloC/Cubit strongly, I did not look at the state management process. I just glanced at how can I use providers, what is the syntax for providers, how can I reach my variable, when I need to use Provider, FutureProvider, etc. All of them are explained in the official Riverpod documentation, so I looked at the official website (riverpod.dev). After I got a general idea, it was time to use the power of the Riverpod for me.
2. Different syntaxes
In Riverpod, there are different text types, both when calling the functions, and when using the states. In bloc, we have to use context to reach BloC or Cubit, but in the Riverpod, we do have not to reach context, since logic three is outside of the Flutter.
3. Documentation
I told you above, Riverpod has nice documentation. Yes, it is, actually. In my opinion, there is a problem after learning Riverpod. When I started learning BloC, there were lots of examples on BloC’s own page. Also, they have their own tutorial for these projects. But in the Riverpod, there are nice examples without the tutorials. Also when I looked the YouTube, I could not find a nice tutorial for it. So, the documentation is good, but not enough I think. It will be improved I think, since the new developers who start the Riverpod, can feel hard to build some things.
In this article, I talked about my experiences. Using Riverpod, I create applications that are NOT counter app, since there are lots of counter app. I have already built 2 applications which are a to-do app and an API-Search app. Also, when I looked on the internet, I could not find nice resources for the StateNotifier + Riverpod + Freezed + DDD (architecture).
@BokanBoris Intermediate - Flutter developer
2 年Very nice.. And what is the best option for you... BLoC or Riverpod? ??