Flutter State Management — GetX

Flutter-logo

Flutter is Google’s open-source tech for building cross-platform apps with a single codebase. It is a full-fledged SDK that includes everything necessary to build a native mobile app.

What is State Management?

State management is the process of maintaining knowledge of inputs across multiple related data flows that form a complete business transaction ( Tom Nolle). For example; when you log on to a website, your information needs to be remembered and different parts of the website may need to get access to your information. In this case, the state is your information, and the process of making sure that it is available to other parts of the website is state management.

GetX

When building apps with Flutter, state can be easily managed by using a framework called GetX which is extra-light yet powerful. It combines high-performance state management, intelligent dependency injection, and route management quickly and practically. Below is a simple example of how GetX helps manage state.

The state (number) is initially 0, the .obs is to say that the state is observable, meaning whenever it changes, the widget observing it will be updated to show the latest state. Any widget that is observing a state must be returned by the Obx widget that comes with GetX. In the above image, the Text widget is displaying the state and that is why it is being returned by Obx.

Conclusion

GetX is a great framework! Using it to manage state removes a lot of boilerplate, simplifies code, and speeds up development.

About the Author