Linked Questions

Popular Questions

Flutter how to force Timer to cancel?

Asked by At

I have a timer that is called from a button OnPressed: startTimeOut(60).

startTimeout(mins) async {

  await subscription.resume();
  print("susbscription started");
  return new Timer(Duration(minutes: mins), handleTimeout);
}
void handleTimeout() async {
    await subscription.cancel().then((_) {

      print("susbscription canceled");
    });

But the user has the possibility to abort the subscription stream by calling startTimeOut(0). In this case "susbscription canceled" get's printed but the first timer call is still active, so the subscription goes on merrily till the 60 minutes are over. Then "susbscription canceled" is printed again.

How could I sort of overwrite/cancel the first call to Timer?

Related Questions