What is GetX State Management in Flutter?

Jay Tillu
5 min readNov 29, 2022

--

GetX State Management by Jay Tillu

State Management is a very hot topic in Flutter. GetX is a great State Management Solution. GetX is not just state management rather it is a micro framework for Flutter. Let’s see how GetX helps you in achieving maximum productivity.

Flutter is a Declarative Framework which means whenever the state changes Flutter does not edit the widget, rather it reconstructs the entire widget with a new value. For Imperative Frameworks like iOS and Android reconstruction of UI is very expensive in terms of performance. But for Declarative Framework like Flutter reconstruction of UI is cheap. Flutter’s Graphic Engine is fast enough to reconstruct the UI.

This reconstruction of UI introduces a concept of State. Developers always searching for a way to manage the State efficiently. Doing State Management in the wrong way makes your app less performant and users will face lagging UI.

Why We Need a State Management Solution?

Default State Management in Flutter uses a Stateful widget and setState() which updates the UI. But this introduces three big disadvantages Code Organisation, Optimisation, and Track of Resource Utilisation. Let’s see these problems in detail:

  • Using too many Stateful Widgets makes your app less performant.
  • Stateful widgets make your code tough to manage and scale as Presentation and Business logic are on the same page.
  • After a certain point of time, it becomes very complex to handle lots of Stateful widgets as your app will change from multiple pages. Track down which page is consuming more RAM and Resources becomes very tough.
  • You ended up with lots of unnecessary widget rebuilding.

What is GetX?

Flutter is an evolving framework. So there is no best State Management approach at the moment. Only your use case can define what is right for you. As of now, Provider is the recommended State Management approach from Google. But there is one strange player who is very powerful and popular. And that is GetX !!

GetX is the most liked Pub Package. Created by an amazing guy Jonny Borges. GetX is a Powerful, Stable, Fast, and Light Weight Flutter Framework. No matter what you do in Flutter, there is always an efficient way to do it in GetX. GetX covers many verticals like:

  • State Management
  • Route Management
  • Dependency Management
  • Internationalization
  • Offline Storage and Many More !!

We will cover all these topics one by one in separate articles.

Why to use GetX?

GetX is Fast, Reliable, and lightweight. It has all the features pre-baked to make your development experience as smooth as possible. Below are some main points to convenience you:

  1. Reduce Third-Party Dependency — GetX makes you less dependent on other packages. Because while developing the apps, you don’t want to be dependent on many third-party packages. GetX gives you major features like State Management, Route Management, and Dependency Management in one package. So you are dependent on only one package rather than three different packages for three tasks.
  2. Less Boilerplate — Flutter reduces development time tremendously but there are some points in which Flutter still finds itself thriving. One of them is Route Management. To simply go to the next page Flutter needs 8 lines of code. With GetX Route Management you just need to call Get.to(OtherPage()) and you are done. Which reduces your development time and gives you amazing development experience.
  3. Best Performance — By default Flutter is known for Performance. It provides you with 60 FPS performance out of the box. But many times due to the developer’s mistake unused resources live in memory. Which kills your performance. This will not happen with GetX, because GetX removes unused resources from memory by default. So you don’t need to worry about closing your streams. GetX automatically does that for you. So by simply using GetX, you are ready to boost performance at its level best.
  4. Code Organisation — GetX allows you to do total decoupling of View, Presentation Logic, Business Logic, Dependency Injection, and Routes. It is made on the foundation of “Complete Separation of View and Business Logic”. But due to Context in Flutter, decoupling is mitigated sometimes. Because to find InheritedWidget, you often need to pass context in View itself. Due to this decoupling becomes a real mess in Flutter. Other State Management Solutions like Provider and BLoC handle this in a very good manner. But GetX gets this to the next level with its reactive state management approach and observable variables. So with a little bit of work, you can achieve total decoupling.
  5. Use only which needed — Although GetX offers a large variety of features, it does not compile everything. All the features reside in separate containers. So if you use State Management then only State Management will compile. Nothing from Route and Dependency Management will compile. Which ensures you about required memory consumption.
  6. Large Community — GetX has a very large and supportive community. It has a large number of Collaborators. They ensure that GetX is always fully compatible with the latest Flutter versions.

During this series of understanding Flutter, we will move forward with GetX. Check out my publication and profile to get the latest posts.

So, guys, that’s it for State Management. Feel free to tell me if I miss something, I’d love to learn it from you. Till then Keep Loving, Keep Coding. And Just like always I’ll catch you up in the next article.

Remember no teacher, no book, no video tutorial, or no blog can teach you everything. As one said Learning is Journey and Journey never ends. Just collect some data from here and there, read it, learn it, practice it, and try to apply it. Don’t feel hesitant that you can’t do that or you don’t know this concept or that concept. Remember every programmer was passed from the path on which you are walking right now. Remember Every Master was Once a Beginner. Work hard and Give your best.

Learn More about Dart and Flutter

Follow me for more such content.

--

--

Jay Tillu
Jay Tillu

Written by Jay Tillu

I am Frontend Web Developer and Hobbyist Blogger. As a Web Developer, I hold expertise in HTML, CSS, JavaScript, and React.

Responses (1)