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();
2.1m questions
2.1m answers
60 comments
57.0k users