0

I am able to run timer when the screen is loaded but I want to run that same timer in background also is there a way to do that? and I also want to convert that 30 to 30 minutes need help.

 static const maxMinutes = 30;
  var minute = maxMinutes;
  Timer timer;
  void initState() {
    // TODO: implement initState
    super.initState();
    startTimer();
  }
  void dispose() {
    // TODO: implement dispose
    super.dispose();
    minute;
    startTimer();
  }
  void startTimer(){
    timer = Timer.periodic(Duration(seconds: 1), (timer) {
      if(mounted) {
        setState(() {
          if (minute > 0) {
            minute--;
          } else {
            timer.cancel();
          }
        });
      }
    });
  }

timer is running but i want to run the timer in background

enter image description here

Md. Yeasin Sheikh
  • 54,221
  • 7
  • 29
  • 56
Saurav
  • 132
  • 1
  • 12
  • Does this answer your question? [How do I run code in the background, even with the screen off?](https://stackoverflow.com/questions/41924890/how-do-i-run-code-in-the-background-even-with-the-screen-off) – Md. Yeasin Sheikh Feb 08 '22 at 05:34
  • The timer should be kept running in the background if you don't dispose of it. – Siddharth Mehra Feb 08 '22 at 05:48
  • 1
    the problem is when i revisit the page the timer starts from the 30 again – Saurav Feb 08 '22 at 05:50

0 Answers0