I have a function named saveData
which is executed on pressing a button. I want if I click on the button I execute saveData function and the value of the button become stop then when I click on stop the function should be fininish.
this is the button code:
Align(
alignment: Alignment.bottomCenter,
child: TextButton(
onPressed: () {
saveData();
},
child: Text('Save Data'),
),
),
3
Answers
You need state management.
State Management
This is a way to manage your user interface controls such as text fields, buttons, images, etc. It controls what and when something should display or perform an action. More about Flutter state management here
Codebase Sample
Now, to implement your idea. You need a bool variable that changes the state on the button click action. To do that, look what I did below
Another way to do this is to create two different functions. One for saving user data, and the other of stop and calling the action based on a bool state.
You can use the method above to update your user data as well if any misunderstand or need future help, comment below. Bye
One way to achieve what you want is simply to create a flag to control which button (text/action) is shown at any given moment:
Try the following working complete sample to see what i mean:
This will produce a result like:
State 1
After Save Data is tapped
Basically this is a state management problem.
you get more information about state management from here
Here a code for solve your problem