Reputation: 21
I have issue to disable the button in its own function when app start button is enable and _enable1=true when I click on it and it should be disable it self but its not working for me
here is my code that i have tried
if(_enable1) {
resendbutoonfunction=() {
print("hello");
setState(() {
_enable1=false;
mycolo=Colors.grey;
});
// timer = Timer.periodic(Duration(seconds: 5), (Timer t) =>disable());
// _controller.forward(from: 0.0);
// timer = Timer.periodic(Duration(seconds: 4), (Timer t) =>timertest());
};
}
here is my button code
onPressed:resendbutoonfunction,
Upvotes: 1
Views: 53
Reputation: 744
In order for you to disable a button, you need to set it to null
resendbutoonfunction() {
print("hello");
setState(() {
_enable1=false;
mycolo=Colors.grey;
});
// timer = Timer.periodic(Duration(seconds: 5), (Timer t) =>disable());
// _controller.forward(from: 0.0);
// timer = Timer.periodic(Duration(seconds: 4), (Timer t) =>timertest());
}
Then for your button:
onPressed: _enable1 ? resendbutoonfunction : null,
Upvotes: 2
Reputation: 1769
As far as I understand your code, as you wrote it, the test (if _enable1), and therefore the definition of the function, is executed only once.
Either the test must be inside the function :
resendbutoonfunction=() {
if (_enable1) {
...
}
}
Or, if your code is executed regularly, then you can change the definition of resendbutoonfunction
if(_enable1) {
resendbutoonfunction=() {
print("hello");
setState(() {
_enable1=false;
mycolo=Colors.grey;
});
// timer = Timer.periodic(Duration(seconds: 5), (Timer t) =>disable());
// _controller.forward(from: 0.0);
// timer = Timer.periodic(Duration(seconds: 4), (Timer t) =>timertest());
};
}
else {
resendbutoonfunction=() {
// do nothing
}
}
Upvotes: 0