Understanding of Flutter State Management Using GetX
Send me Nitor Infotech's Monthly Blog Newsletter!
×
nitor logo
  • Company
    • About
    • Leadership
    • Partnership
  • Resource Hub
  • Blog
  • Contact
nitor logo
Add more content here...
Artificial intelligence Big Data Blockchain and IoT
Business Intelligence Careers Cloud and DevOps
Digital Transformation Healthcare IT Manufacturing
Mobility Product Modernization Software Engineering
Thought Leadership
Aastha Sinha Abhijeet Shah Abhishek Suranglikar
Abhishek Tanwade Abhishek Tiwari Ajinkya Pathak
Amit Pawade Amol Jadhav Ankita Kulkarni
Antara Datta Anup Manekar Chandra Gosetty
Chandrakiran Parkar Dr. Girish Shinde Gaurav Mishra
Gaurav Rathod Harshali Chandgadkar Kapil Joshi
Madhavi Pawar Marappa Reddy Milan Pansuriya
Minal Doiphode Mohit Agarwal Mohit Borse
Nalini Vijayraghavan Neha Garg Nikhil Kulkarni
Omkar Ingawale Omkar Kulkarni Pranit Gangurde
Prashant Kamble Prashant Kankokar Priya Patole
Rahul Ganorkar Ramireddy Manohar Ravi Agrawal
Robin Pandita Rohini Wwagh Sachin Saini
Sadhana Sharma Sambid Pradhan Sandeep Mali
Sanjeev Fadnavis Saurabh Pimpalkar Sayanti Shrivastava
Shardul Gurjar Shravani Dhavale Shreyash Bhoyar
Shubham Kamble Shubham Muneshwar Shweta Chinchore
Sidhant Naveria Sreenivasulu Reddy Sujay Hamane
Tejbahadur Singh Tushar Sangore Vasishtha Ingale
Veena Metri Vidisha Chirmulay Yogesh Kulkarni
Mobility | 07 Dec 2022 |   9 min

Understanding Flutter State Management Using GetX

featured image

When the creation of an application is kickstarted in Flutter, the all-important decision that needs to be made is: which state management must be used.

I hope reading today’s blog will make it easier for you to make this decision! For starters, let’s delve into what GetX is.

What is GetX?

GetX is not only a state management library, but a microframework combined with route management and dependency injection. It provides some utility functions like theme change and languages change.

Let’s start exploring it in today’s blog!

GetX is built on three basic principles:

Three Principles of GetX:

  • Performance: GetX mainly focuses on better performance and minimum usage of resources, so in my humble opinion, it’s the best among other state management techniques.
  • Productivity: GetX has easy-to-remember syntax besides its top-notch performance. It saves a lot of time for the developers and increases the speed of the app by reducing the usage of resources.
  • Organization: GetX allows us to do away with business logic on views and separate dependency injection and navigation from the UI. You don’t require the context to navigate between screens. You don’t need to inject your controllers/models/blocs classes into the widget tree via multiproviders. For this GetX uses its own dependency injection feature.

Take a look at this comparison with other popular state management plugins:

RAM Usage Chart of Flutter State Managers

How to add GetX in your project:

Add ‘get: ^latest_version’ in your ‘pubspec.yml’ file or you can open a terminal with your project path and write the command: ‘flutter pub add get’. This way, you can easily add a Getx plugin in your project.

Now let me tell you some more about the features of GetX.

Features of GetX:

State Management:

There are so many State Management libraries available in Flutter like BLoC, Provider etc. If you are new to flutter, please check this blog if you’d like to learn about Flutter state management.

State Manager:

GetX has the GetBuilder which is used to make UI screens or views interact with the variables and methods on the controllers and make changes accordingly.

To notify the widget, GetX provides an update () method. The update () method notifies the getxBuilder and provides updated value.

For example: We created a counterController that extends GtexController. In this controller we define our business logic.

class CounterController extends GetxController {

var counter = 0;

increment() {

counter++;

update();

}

}

Now we create a widget to use this controller and use their method.

GetBuilder<CounterController>(

init: CounterController(),

builder: (value) {

return InkWell(

onTap: controller.increment,

child:Text(

' ${value.counter}',

style: Theme.of(context).textTheme.headline4,

)

);

},

);

Route Management

It is pretty easy to manage routes using GetX. Previously it was quite difficult to manage it. Here is the general way:

Navigator.of(context).push(MaterialPageRoute(builder: (context) => NewScreen()));

This way, you must pass the context and define MaterialPageRoute but in GetX it just two words.

Get.to(NextScreen());

So, it is pretty easy compared to the standard way. Simplify your Flutter code with GetX.

Comparison of Flutter Code & Flutter Code with GetX

Theme Management

Using GetX makes it easy to manage the theme. With the help of GetX you must define the themes in GetMeterialApp() in this component define both themes – light and dark. If you want to switch the theme, you just have to write single line code to change the theme.

Get.changeTheme(ThemeData.light());

Localization

Using GetX is easy to manage multiple languages in your application. In your application you must define a language file with translations, for example:

import 'package:get/get.dart';

class Languages extends Translations {

@override

Map<String, Map<String, String>> get keys => {

'en_US': {

'login': 'Login',

'register': 'Register',

'forgot': 'Forgot ?',

'username': 'Username',

'language': 'Language',

'change_lang': 'Changes Language',

},

'es_ES': {

'login': 'Acceso',

'register': 'Registro',

'forgot': 'Olvidó ?',

'username': 'Nombre de usuario',

'language': 'Idioma',

'change_lang': 'Cambios de idioma',

},

'ru_RU': {

'login': 'Авторизоваться',

'register': 'регистр',

'forgot': 'забыл ?',

'username': 'Имя пользователя',

'language': 'Язык',

'change_lang': 'Изменяет язык',

}

};

}

Now, you must use this string like in this example.

Text(‘login’.tr);

You must add .tr after your string, make sure you had defined it in language file. After this you must set your local to GetMetiralApp. Also, if you want to change your language from English to Spanish or Russian, just change local to your desired language.

Get.updateLocale(const Locale('en', 'US'));

Now that you are familiar with the features of GetX, let’s discuss the pros and cons of GetX.

Pros:

  1. It is very easy to use and implement if you are new to Flutter.
  2. It provides very short code.
  3. Getx is very popular, so you will get large support.
  4. It provides large support of functionality like State, Navigation, Dependency and Utility.

Cons:

  1. The package solves several issues in just a single huge bundle.
  2. The package is too big and has an excessive number of issues.
  3. When you face an issue, you must wait for a very long time for a fix.

I must mention that I have gone through most of state management like flutter_bloc, provider, and riverpod. But among these, GetX is easy to understand and easy to use in your project.

Send us an email with your thoughts about Flutter GetX and visit us at Nitor Infotech to discover details about our offerings.

Related Topics

Artificial intelligence

Big Data

Blockchain and IoT

Business Intelligence

Careers

Cloud and DevOps

Digital Transformation

Healthcare IT

Manufacturing

Mobility

Product Modernization

Software Engineering

Thought Leadership

<< Previous Blog fav Next Blog >>
author image

Milan Pansuriya

Lead Engineer

Milan Pansuriya, a Lead Engineer at Nitor Infotech, has 7 years of experience in mobile application development. For mobile application development, he has worked on Android with Kotlin and Java. For cross platform development, he has worked on Flutter and React Native. He has also worked on e-commerce mobile application development. He is passionate about the latest technology and loves to explore Stack Overflow in his free time.

   

You may also like

featured image

A Complete Guide to Monitoring Machine Learning Models: Part 2

In the first part of this series, I introduced you to the monitoring of machine learning models, its types, and real-world examples of each one of those. You can read Read Blog


featured image

Building and Managing AI Frameworks

I’m sure you would concur when I say that reliable AI is well on its way to becoming a vital requirement in today’s business landscape. Its features of fairness, explainability, robustness, data li...
Read Blog


featured image

Top 4 Types of Sentiment Analysis

When you’re analyzing what works for your business and what doesn’t, you deal with two types of data- objective, tangible data that you collate from surveys, feedback, and reviews, and then there’s...
Read Blog


subscribe

Subscribe to our fortnightly newsletter!

We'll keep you in the loop with everything that's trending in the tech world.

Services

    Modern Software Engineering


  • Idea to MVP
  • Quality Engineering
  • Product Engineering
  • Product Modernization
  • Reliability Engineering
  • Product Maintenance

    Enterprise Solution Engineering


  • Idea to MVP
  • Strategy & Consulting
  • Enterprise Architecture & Digital Platforms
  • Solution Engineering
  • Enterprise Cognition Engineering

    Digital Experience Engineering


  • UX Engineering
  • Content Engineering
  • Peer Product Management
  • RaaS
  • Mobility Engineering

    Technology Engineering


  • Cloud Engineering
  • Cognitive Engineering
  • Blockchain Engineering
  • Data Engineering
  • IoT Engineering

    Industries


  • Healthcare
  • Retail
  • Manufacturing
  • BFSI
  • Supply Chain

    Company


  • About
  • Leadership
  • Partnership
  • Contact Us

    Resource Hub


  • White papers
  • Brochures
  • Case studies
  • Datasheet

    Explore More


  • Blog
  • Career
  • Events
  • Press Releases
  • QnA

About


With more than 16 years of experience in handling multiple technology projects across industries, Nitor Infotech has gained strong expertise in areas of technology consulting, solutioning, and product engineering. With a team of 700+ technology experts, we help leading ISVs and Enterprises with modern-day products and top-notch services through our tech-driven approach. Digitization being our key strategy, we digitally assess their operational capabilities in order to achieve our customer's end- goals.

Get in Touch


  • +1 (224) 265-7110
  • marketing@nitorinfotech.com

We are Social 24/7


© 2023 Nitor Infotech All rights reserved

  • Terms of Usage
  • Privacy Policy
  • Cookie Policy
We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it. Accept Cookie policy