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.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Satheesh Guduri
Satheesh Guduri

Written by Satheesh Guduri

Mobile App Developer and Trainer

No responses yet

Write a response