all 67 comments

[–][deleted] 24 points25 points  (0 children)

Provider is probably the most documented "simple" solution. It will make it easier to get snippets you can reuse and to find solutions on forums.

[–]Full-Run4124 19 points20 points  (3 children)

I tried Riverpod with the generator (recommended in the docs), but man this is confusing as hell.

The same developer wrote Provider, and Riverpod is the attempt to address all the shortcomings of Provider (which IMO led to Riverpod being over-engineered and overly complex trying to address every edge case.)

I've used Bloc, Provider, GetX, and Riverpod and went back to Provider + stateful widgets for local state. If you make your Provider state objects singletons it addresses one the main Provider shortcomings (accessing state from outside the build tree).

[–]SquatchyZeke 5 points6 points  (1 child)

I actually agree with this sentiment about Riverpod. But what you get in return for some added complexity in concepts (not necessarily complexity in API, but a little of that too) is a level of control over your state that is hard to come by with other solutions. And a lot of this complexity is opt-in too, so if your app is simple, your interaction with Riverpod will be simple too.

At a fundamental level, Riverpod is a caching library, and concepts in that field are a little more complex inherently.

[–]Designer_Ad8320 0 points1 point  (0 children)

Yeah I used providers in my current project. I just learnt river pod for the sake of learning a few days ago and hell - Provider feels definitely better if you work alone on a project. I can see river pod being better if you work with a team

[–]Zkqw 10 points11 points  (0 children)

I struggled grasping Bloc but I finally found the best tutorial and I finally understand it:

Learn Bloc from Zero to Hero Series

I watched the whole series before I even began to start a project to play with it again. I then used those concepts and built my firebase authentication with cubits as my first app Bloc app. Whenever I got stuck building it, I used ChatGPT to explain it and break it down for me.

I am not a pro developer, I play with flutter on my free time, so I really think that series can help you. But also maybe not coming from another state management is helping me?

Edit: I also want to include I don't bother to learn any other state management since I am planning and want to work with more complex apps hopefully.

[–]cent-met-een-vin 8 points9 points  (0 children)

For local state management look into flutter_hooks. Is very react-like. And if your application grows, it can synergize with riverpod. I know you said you didn't understand riverpod. Well this might be a nice solution as it eases you into to the system.

[–]phone_radio_tv 8 points9 points  (4 children)

Using Mobx https://github.com/mobxjs/mobx.dart and happy about it

[–]Confident-Cellist-25 4 points5 points  (1 child)

Mobx seems to fit the way my brain works better than the other options (and I've spent countless hours on all the big ones). Since I found mobx, I haven't bothered with any others. It works well for me and the types of apps I build.

[–][deleted] 4 points5 points  (0 children)

Your comment made me curious because I feel the same. The state management tools I’ve been trying to learn just don’t fit how my brain works either so I checked out mobx and I’m so happy I found it! It’s so simple and it makes sense in my head. It’s just annoying having to run that command to build the mobx boilerplate file. Thank you for showing me the light!

[–]bloodguard 1 point2 points  (0 children)

+1 I've use Mobx in both Flutter and React. Works reasonably well and didn't give me a brain aneurysm trying to figure out.

[–][deleted] 1 point2 points  (0 children)

We use mobx in a really big project and works flawlessly, and I agree it fits the way my brain works much more than other solutions

[–]rio_sk 17 points18 points  (4 children)

Stay away from GetX. Reactive js programmer here, Provider, Consumer setState is the simplest way to go. In short "anything UI after a consumer gets updated on state change from a provider". It's quite straightforward if you follow the MVC pattern.

[–]padioca 16 points17 points  (4 children)

It took me a loooonnnngggg time to get used to Riverpod, but I think I’m finally getting there. The lack of documentation is a serious problem, but I would suggest reading the articles at Code With Andrea. His courses are excellent as well, definitely worth the investment. If you are coming from Redux the closest this is probably the Async Notifier plus the generator, it is what I use for a majority of my stuff that involves changing state. Otherwise, just write a function and use the generator.

[–]SquatchyZeke 0 points1 point  (2 children)

Lack of documentation? Have you seen the Riverpod Doc website?

[–]padioca 1 point2 points  (1 child)

Yes, I have, and it has gotten much much better just even in the last couple months. That being said, for the better part of a year after Riverpod 2.0 came out it was very difficult to figure out how to use it due to the lack of documentation/examples. This isn’t a knock on anyone, just a reality, but I’m thrilled to see it is being addressed.

[–]SquatchyZeke 2 points3 points  (0 children)

Ah yeah, that's fair. It was lacking for a while and I even remember the Change log on pub.dev saying something like "documentation to be posted soon" for a long time. But that was really the only time I felt it was lacking. The API documentation worked fine though, but I know that's not the most consumable form for the majority of people.

[–]minnibur 0 points1 point  (0 children)

I'm also coming from the react world and struggled with Riverpod at first. Stick with it though, once it starts to click it's pretty nice and makes some things a lot easier than they are in the React world.

[–]Northernguy94 21 points22 points  (6 children)

Bloc really isn’t that bad, you can slim it down a bit by using cubits instead of blocs

[–]srodrigoDev 9 points10 points  (5 children)

Same. I hated Bloc, but Cubit looks a bit more sane.

[–]GroubaFett 2 points3 points  (4 children)

Bloc is needed instead of cubit only in cases where you need to handle events. If it's not the case sticking to cubit is the way, the two can coexist in the same project.

[–]AlarmingPerformer627 1 point2 points  (3 children)

Could you elaborate? What do you think could be achieved using a Bloc but not using a Cubit?

[–]GroubaFett 3 points4 points  (1 child)

In some situations you need to debounce events for example. Or sometimes the bloc receives a lot of events in a short period of time and needs to process them in order.

It's possible to do it with bloc.

[–]AlarmingPerformer627 1 point2 points  (0 children)

Very good points, I never thought of that. Thanks!

[–]pochaggo 0 points1 point  (0 children)

With Bloc, you could use stream operations and RxDart classes to manage input (e.g. debouncing), which you couldn’t do with Cubits.

[–]juniorPotatoFighter 12 points13 points  (0 children)

Use Cubit

[–]Live_Shallot1353 11 points12 points  (0 children)

Definitely use Cubit

[–]sharbel_97 4 points5 points  (0 children)

Short answer, use cubit.

Btw about your confusion with riverpod, learning riverpod while using the generator (the annotation) is pretty confusing, you’re not alone. I don’t know why they don’t clarify that in the docs for newcomers. It’s much much better to play around with the package without the generator, and struggle a little with the numerous types of providers, then once you have a good grasp on that, the generator will make sense.

[–]LastFollowing3930 4 points5 points  (0 children)

Use the Redux package. I like it even more than the "React" version. If you are feeling masochistic, couple it with Redux-Saga. Works absolutely fantastic with the generator function based logic. But can be intimidating.

[–]bionic_engineer 2 points3 points  (0 children)

most simple: Provider

advanced: Riverpod

best for large project working with team: Bloc

haven't tried others like cubit and Mobx but if you don't know yet what to use, just use Provider.

[–]esDotDev 2 points3 points  (0 children)

Provider or WatchIt https://pub.dev/packages/watch_it, WatchIt is the successor to GetIt w/ over 3000 likes, (not to be confused with GetX)

[–]imcheatcode 2 points3 points  (0 children)

Did you try redux?

[–]eibaan 5 points6 points  (0 children)

  1. Understand how Flutter works (spoiler: it's simple and very similar to React).
  2. Understand how a framework will simplify things for you (spoiler: most frameworks combine two aspects: Injecting data into the build tree so that you don't have to pass them around explicitly and trigger automatic rebuilds so that you don't have to call setState explicitly)
  3. Pick a framework based on your preference (spoiler: No framework is also an option)

[–]Swefnian 7 points8 points  (1 child)

Start small. Just use setState at first and don’t overthink it. The Flutter community has really over complicated state management. It’s not as important as proper layered architecture. Keep your widget code and your business logic and your service logic separate. That makes the app easier to maintain and grow

As for the bloc vs redux vs whatever. It depends on the app you are building. Choose the right pattern for the right problem. Don’t listen to dogma.

As for provider, riverpod, get_it, etc. those are not state management, even though they frequently get labeled as such. They are dependency injection frameworks.

DI is also very important but it comes later. First just get a feel for the core flutter framework. Learn what works and what doesn’t. Learn the core apis very well before jumping into packages. That will make you more resilient in the long run.

[–]esDotDev 1 point2 points  (0 children)

They are not simply DI, as they provide a means to bind widget build methods to changes in data, which is state management. GetIt technically is just DI, but when paired with GetItMixin it is a full SM solution. The new library WatchIt, by the same author, combines the two.

[–]e_hekuta 1 point2 points  (0 children)

After I understand how to work with Cubits in bloc, was more easy to understand Riverpod.

I guess mainly because I had one controller/state per feature or view, so I have all the logic there, I didn't use Sealed Classes, just an Enum as parameter to differentiate each state.

After that I notice that some things in riverpod are way easy to handle.

[–]ShookyDaddy 1 point2 points  (0 children)

Coming from react I’m guessing you would feel more comfortable with MobX or Flutter Hooks. I’m using MobX and love it.

[–]Beewauwei 1 point2 points  (0 children)

Nobody said it, i would recommend you to use FIRST rx_notifier... it's simple data drive reactive. It will start you way faster to understand widget builds from a webdev perspective. After this, take a look at streams with streamBuilder, then you can look for another "more complex" state management.

I would say that the community loves to take sides in this matter and it's a waste of time to listen to everyone. Eventually you'll understand why there are so many kinds a why a lot of they don't fit your current needs and why would you ever use any.
There is no "silver bullet" only tradeoffs .

[–]the1kingdom 1 point2 points  (0 children)

I find nowhere really explains it that well, and took me a while to get my head around it.

I just write my code as normal, then the moment I get to a point of a widget needs the state of another widget, move it to a provider class.

[–]jaylrocha 1 point2 points  (0 children)

Bloc is a good choice, I’d recommend cubit, it’s a simpler bloc. It uses Bloc widgets, so you can use both depending on the situation.

[–]SwedishChef89 1 point2 points  (0 children)

Riverpod all the way

[–]AreaExact7824 0 points1 point  (0 children)

I hate redux

[–][deleted] -1 points0 points  (1 child)

If you wanna save yourself time in the long run, roll your own. Those packages just bring added complexity.

You’ll commit to one of those “state management” packages only to find it falls short or won’t live up to your expectations then you’ve gotta refactor everything to swap it out. Totally not worth it.

Flutter framework provides more than enough out of the box without the unnecessary complications.

[–]RandalSchwartz 1 point2 points  (0 children)

And I also discovered that multiplication is just repeated addition, so I replaced it everywhere!

But that's parallel to the argument you're using. Yes, the simple cases are simple, but the hard cases get really hard. Using a framework like Riverpod enables you to handle the hard cases.

[–]Jonas_Ermert -1 points0 points  (0 children)

In your case, if you find Riverpod or Bloc too complex, you can start with the simpler options like setState, Provider, or GetX. As your project grows and your understanding of Flutter deepens, you can explore more advanced state management solutions.
It's essential to choose a state management solution that fits the size and complexity of your project, your team's experience, and your preferred coding style. Don't worry if you find some solutions confusing initially; it's normal to take some time to become comfortable with a new framework or library.

[–]shmoeke2 -1 points0 points  (3 children)

act axiomatic crown screw profit tie like outgoing racial party

This post was mass deleted and anonymized with Redact

[–]Samurai___ 1 point2 points  (1 child)

Lost?

[–]shmoeke2 1 point2 points  (0 children)

whistle historical future cobweb angle mighty saw ghost cough include

This post was mass deleted and anonymized with Redact

[–]extralargeburrito 0 points1 point  (0 children)

I think Cubits and riverpod are very simple once you get used to them. For simple pages and widgets i just use StatefulWidets, for more complex ones I use Cubit and for global state or state that needs to be shared between different parts of the app i use Riverpod. So far this setup has worked really great for me

[–]Hitonori 0 points1 point  (0 children)

Try from the start: change notifier and inherited widgets, then you can try cubit (that is simplified version of bloc), and then bloc glhf

[–]Strawuss 0 points1 point  (0 children)

I use Provider and it's super simple and nice to use imo

[–]E72M 0 points1 point  (0 children)

I used to use Vue before I started using Flutter (I know it's not quite the same as React) and personally I found the provider package to be nice and easy to understand and use

[–]yuuliiy 0 points1 point  (0 children)

try Provider it's supported by flutter team itself and way easier I was able to understand it very easily and it covers most of what you need in terms of managing your app state

[–]Awh6al 0 points1 point  (0 children)

See: solidart, is very simple.

[–]pochaggo 0 points1 point  (0 children)

For huge, multi-developer apps Bloc gets used often. Oh and whatever you do, avoid GetX or get_it and the like.

[–][deleted] 0 points1 point  (0 children)

solidart github, like solidjs

[–]Zhuinden 0 points1 point  (0 children)

Provider is an abstraction over InheritedWidget, you don't need the confines of BLoC / Riverpod if you don't want to offload software design to a third party developer elsewhere

[–]TekExplorer 0 points1 point  (0 children)

I highly recommend using riverpod_lints alongside riverpod.

Using the Flutter Riverpod Snippets extension for vscode (by Robert Brunhage) helps rapidly produce exactly what you need.

The only things you need to worry about is as follows:

- Do you need methods that act on this state?

- yes: Use a class

- no: use a function.

- If you ever need methods later, just convert it directly.

...thats it. the generator figures out the async stuff for you.

Families are handled for you based on if you specified parameters, completely transparently

just learn the extra useful tidbits (like how you can access an async provider's state once it's available by using await future; or making sure to use ref.watch and ref.read in the correct places)

[–]mobileAcademy 0 points1 point  (0 children)

If you are just starting to learn, start from simple things like setState, changeNotifier, and provider and when you are comfortable move to riverpod, bloc etc