how can i cancel Future.delayed
i am using Future.delayed for some task, but if i want to cancel this delayed task, so is their any method or any other things to use.
Future.delayed(Duration(seconds: 10),(){
setState(() {
//some method calling
});
});
what about declare a bool value
bool _executeFuture=true;
then
Future.delayed(Duration(seconds: 10),(){
if(_executeFuture){
setState(() {
//some method calling
});
}
});
Now whenever you want to cancel Future just use
_executeFuture=false;
Also, You can use CancelableOperation from https://pub.dartlang.org/packages/async
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With