How can I cancel/stop a Future.delayed? I read this other question: how can i cancel Future.delayed function calling and someone answered with this possible solution: https://dart.academy/how_cancel_future/, but I don't know how to use it in my code, I don't have a List of Data like the example, I just don't want the code inside the Future.delayed be executed in certain case.
await Future.delayed(Duration(seconds: myDuration)).then((_){ checkAnswer(""); jumpToNextQuestion(); });
Use a Timer.
Timer
Timer t = Timer(Duration(seconds: myDuration), () { checkAnswer(''); jumpToNextQuestion(); }); // and later, before the timer goes off... t.cancel();
1.4m articles
1.4m replys
5 comments
57.0k users