Getx for state change with simple example

Satheesh Guduri
2 min readDec 7, 2020

--

before reading this article please read this below article .

In the last article i told you that use setState() method to change the state of a button. But here we are using getx dependency for state management.

add this dependency to your app.

get: 3.15.0

First step, simply put the string in observation.

var buttonName = "edit".obs;

Second step, here we are changing the button Name.

TextField(

onChanged: (value) {
if(value.length>0){
buttonName.value ="save";
}else{
buttonName.value = "edit";
}
},

finally, when the buttonName changes the widget has to observe.

Obx(()=>RaisedButton(
color: AppColors.editButtonColor,
child: Text('$buttonName')));

Here we are not using setState( ) to update the button text instead of that simply we are wrapping our widget with Obx(() =>).

If you found this article helpful click and hold 👏 a button and show some love and help others to find this article.

Feeling more generous, you can buy me a cup of tea.

--

--

Satheesh Guduri
Satheesh Guduri

Written by Satheesh Guduri

Mobile App Developer and Trainer

No responses yet