Why GetX Is The Best State Management For Flutter App

Gbolahan
2 min readJun 20, 2021

--

what are the state management options we are provided with in flutter.

  1. Provider — A wrapper around Inherited Widget to make them easier to use and more reusable. By using Provider instead of manually writing Inherited Widget.
  2. setState — The low-level approach to use for widget-specific, ephemeral state
  3. inheritedWidget & inheritedModel — The low-level approach used to communicate between ancestors and children in the widget tree. This is what Provider and many other approaches use under the hood.
  4. Redux — A state container approach familiar to many web developers and should remain in the web world.
  5. Fish -Redux — Fish Redux is an assembled flutter application framework based on Redux state management. It is suitable for building medium and large applications.
  6. GetIt — A service locator based state management approach that doesn’t need a BuildContext.
  7. MobX — A popular library based on observables and reactions.
  8. Bloc — A family of stream/observable based patterns.
  9. RiverPod — An approach similar to Provider that is compile-safe and testable. It doesn’t have a dependency on the Flutter SDK.

Now, why GetX is the best in my opinion

  1. Update only the required widgets.
  2. Does not use changeNotifier, it is the state manager that uses less memory (close to 0mb).
  3. Forget StatefulWidget! With Get you will never need it. With the other state managers, you will probably have to use a StatefulWidget to get the instance of your Provider, BLoC, MobX Controller, etc. But have you ever stopped to think that your appBar, your scaffold, and most of the widgets that are in your class are stateless? So why save the state of an entire class, if you can only save the state of the Widget that is stateful? Get solves that, too. Create a Stateless class, make everything stateless. If you need to update a single component, wrap it with GetBuilder, and its state will be maintained.
  4. Organize your project for real! Controllers must not be in your UI, place your TextEditController, or any controller you use within your Controller class.
  5. Do you need to trigger an event to update a widget as soon as it is rendered? GetBuilder has the property “initState”, just like StatefulWidget, and you can call events from your controller, directly from it, no more events being placed in your initState.
  6. Do you need to trigger an action like closing streams, timers and etc? GetBuilder also has the dispose property, where you can call events as soon as that widget is destroyed.
  7. Use streams only if necessary. You can use your StreamControllers inside your controller normally, and use StreamBuilder also normally, but remember, a stream reasonably consumes memory, reactive programming is beautiful, but you shouldn’t abuse it. 30 streams open simultaneously can be worse than changeNotifier (and changeNotifier is very bad).
  8. Get is omniscient and in most cases it knows exactly the time to take a controller out of memory. You should not worry about when to dispose of a controller, Get knows the best time to do this.

--

--

Gbolahan
Gbolahan

Written by Gbolahan

I'm a Mobile Developer (Flutter) , Interested In science and how it's suppose to help.

Responses (6)