Read More
Read now

GetX In Flutter

Save

Before starting our blog topic GetX In Flutter, let’s discuss GetX. What is GetX and why we need it in the flutter? It is basically an extra-light flutter framework, which can be used for State Management, Dependency Management, and Navigation Management. GetX works on 3 principles: PRODUCTIVITY, PERFORMANCE, and ORGANIZATION.

Let’s start the implementation of the GetX in our flutter project and get to know what features it provides in order to enhance the coding practice and code optimisation.

1. Adding the Get dependency in the “pubspec. yaml”

I have used the following version dependency, you can use any version as per your requirement from the Flutter Dev console.

2.Import get in files that it will be used

You have to import this package into your dart class:

Now, let check what features we can implement with the help of GetX in the flutter with writing the minimal number of code and with better secure logic.

1. Navigate to a new screen:

Before the Get package, we are using Navigator class and its push & pop methods for navigating to a new screen or return back from it. But with the help of the GetX package, we can do it easily.

> Convert MaterialApp into the GetMaterialApp before proceeding

> Redirecting to the next screen (ScreenB in my case)

> Navigating to the screen with the name

> Getting back from any screen

> Navigating to the new screen with killing all the previous screens, we can use following method:

2. State Management

For managing the state in a flutter, GetX has two different state managers, the simple state manager (we’ll call it GetBuilder) and the reactive state manager (GetX/Obx). GetX turns reactive programming into a simple way. Let’s demonstrate with an example:


1. I have created a model class call it User in which I have defined a variable name

2. Define the controller for it.

3. Then in the widget where you want to update the changes in the value, you can use following function for it:

Conclusion:

There are many uses of the GetX in flutter which make the code simpler and easy to use with a minimal line of codes. You can use this package as per your need.

Hope this blog helps you to understand the basic uses of the GetX In Flutter.

Thank you for reading!!

For more information, you can visit the Dev Console.

. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

css.php

Big thanks to Webkul and his team for helping get Opencart 3.0.3.7 release ready!

Deniel Kerr

Owner and Founder. Opencart

Talk to Sales
Start a Project

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home