0

I want Run Timer In Background also even if user closed app. And don't stop until user do not stops even app closed. I tried stream but it stop when app closed. So Please Help me. Thanks in advance.

Harsh Sureja
  • 1,052
  • 1
  • 9
  • 22
  • Does this answer your question? [How to run clock timer in background on flutter?](https://stackoverflow.com/questions/59480124/how-to-run-clock-timer-in-background-on-flutter) – Ardeshir ojan Jun 02 '21 at 04:54

2 Answers2

0

Try using this package - https://pub.dev/packages/android_alarm_manager

I'm also attaching this video, this can solve your problems - https://youtu.be/A4_L959tRuM

Shreyansh Sharma
  • 1,588
  • 2
  • 17
  • 42
0

Thank you for giving answer

But I find solution like current time save in local device using SharedPreferences and when user open app again then find difference between saved time and currenttime show in my app

here is my code

    startTimer() {
    timerStream = stopWatchStream();
    timerSubscription = timerStream.listen((int newTick) {
      String time = _sharedPreferences.getString("time");
      Duration duration = DateTime.now().difference(DateTime.parse(time));

      setState(() {
        hoursStr = ((duration.inSeconds / (60 * 60)) % 60)
            .floor()
            .toString()
            .padLeft(2, '0');
        minutesStr =
            ((duration.inSeconds / 60) % 60).floor().toString().padLeft(2, '0');
        secondsStr =
            (duration.inSeconds % 60).floor().toString().padLeft(2, '0');
      });
    });
  }
Harsh Sureja
  • 1,052
  • 1
  • 9
  • 22