In the previous part, we went through the introduction for the GetX package and explored the usage of some GetX methods. Now, we are getting to explore more on implementation of GetX State Management in Flutter. In GetX State Management, business logic is separated from views while dependencies also can be separated using bindings. you’ll refer the previous article here.

Learn more about the package from offical Site in details https://pub.dev/packages/get

GetBuilder

GetBuilder is employed to form UI Screens or views interact with the variables and methods on the controllers. From here, we will call functions and hear the changes in states. GetBuilder is that the best way for managing ephemeral state.

return GetBuilder<CounterGET>(
init: CounterGET(),
builder: (controller) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text( controll.count.toString(),
style:TextStyle(fontSize: 20),),
RaisedButton(child: Text('Go'),
onPressed: () {
//we will call our incremnet method here
controll.increment(); })], );
});

GetxController

GetxController may be a class where our business logic is defined and every one our variables and methods are declared to be used from the UI. Each controller class extending from GetxController offers a disposable interface which reduces the manual task of disposing the controller whenever a widget is faraway from navigation stack. GetxController comes with lifecycle which replaces methods of StatefulWidgets.

Update(): Using this, widgets can hear the changes made by the methods defined in controller. it’s almost like notifyListeners in providers

onInit(): it’s called immediately after the widget is allocated memory.

onReady(): it’s called immediately after the widget is rendered on screen.

onClose(): it’s called just before the controller is deleted from memory.

class CounterGET extends GetxController{ var count = 0; void increment() { count++; update(); //for notify the widget or update the widget } }

class CounterGET extends GetxController
{
var count = 0;
void increment() {
count++;
update(); //for notify the widget or update the widget
}
}

Obx

This is used in case if we want to use multiple controllers.

var count = 0.obs
Obx(()=> Text(count.string));

THANK YOU

#flutter​ #fluttertutorials #getX

For more interesting videos and pics.

SUBSCRIBE on YOUTUBE

https://youtube.com/channel/UCyRt3BNQhVnYmfwVeMQAOxw

CONNECT on LINKEDIN

https://www.linkedin.com/in/sanchitsaran​

FOLLOW on GITHUB

https://github.com/SanchitSaran

FLUTTER | ANDROID | WEB | UI/UX | YOUTUBER | ARTIST