Flutter State Management: Controversial Topic

Flutter State Management: Controversial Topic

·

2 min read

Before Jumping into the topic Let's clarify why we need State Management Solution for Our App.

Not Only Mobile Apps and web apps also need State Management. But Webpage Don't. But Why?

In Single Page Applications UI have to change according to certain data changes. There all UI changes happen on a single page, but in the case of a webpage, it redirects to another statically created webpage such as .php or .html etc. Single Page Applications are dynamic they change as data changes.

But how State Management Solution comes into the picture for this?

In Simple Terms, State Management is Controller for UI, It handles when UI should rebuild.

What State Management Solution Do We Have in Flutter?

  1. setState()

    It is provided by Flutter. For Small Projects, it does a great job. When it is called it rebuilds the whole widget.

  2. Provider

    The provider is State Management Solution created by Remi Rousselet. By using provider developers have to ability to separate the UI and logic easily. Provider data can be used Anywhere it is not limited to widgets only. It uses an Inherited widget. In short, it depends on the flutter framework.

  3. BloC

    Bloc is another State Management Solution for Flutter. It works in Stream, any changes in data immediately rebuild the UI. It is industry standard. Many Developers Prefer Bloc.

  4. Riverpod

    Riverpod is Created By the Same Person Who Created Provider. Buy why is need of new package? Because the Provider was dependent on Flutter Framework and it causes issues like the provider not being found. Riverpod is independent from the Flutter framework.

  5. GetX

    GetX is widely Popular among beginner Flutter App Developers. It doesn't mean that experienced developer doesn't use GetX. They use it.

So Why there is Fight for Which State Management is Best.

There is no reason to fight over a state management tool. It just an architectural way. You can use any state management tool as you need.

But Don't Use GetX

Many Beginner who comes into Flutter most likely use GetX for State Management. Because it makes everything easy to do. You Can Access Context anywhere beginner find it handy but it is bad practice. For Shake for learning it's good but In Production App GetX may cause memory leaks and context issues.

So, What do I prefer

I prefer Riverpod, It doesn't mean you should also. I recommend you go with Riverpod or BloC. They have good community support. Easy Follow Documentation.