I want to implement Timer in flutter that is capable of running in background despite when the phone is locked. I have tried Timer.periodic and isolates but both of them do not run in background or when the phone is locked. And also I also came across the logic of saving the timestamp when going to background and comparing that same time while coming to foreground, but that is not feasible in my case. So Anything else do you know apart from these would be helpful.
Asked
Active
Viewed 33 times
0
-
You generally don't get background execution as you wish on mobile, because it kills batteries. This question has been asked and answered many times before, with the same answers repeatedly. – Randal Schwartz Aug 30 '23 at 08:23
-
only provide solutions if you really have otherwise dont waste time here in giving vague statements. @RandalSchwartz – Nadeem Shaikh Aug 31 '23 at 05:38
-
this was a comment, not a solution. It was a comment about the quality and redundancy of the question. – Randal Schwartz Aug 31 '23 at 23:09
-
this was a comment, not a solution. It was a comment about the quality and redundancy of the question. – Randal Schwartz Aug 31 '23 at 23:09
1 Answers
0
Store the value in cache when you start your timer and when you stop your timer, you differentiate between now and the value you stored in cache.

Antonin Liehn
- 9
- 3
-
this is not feasible for my usecase and I have already mentioned this in the description. – Nadeem Shaikh Aug 30 '23 at 10:11
-
Sorry, i don't understand that. I found an article that talks about the same problem as you, and the answer is interesting https://stackoverflow.com/a/59480263/18290590 And article explain what to do countdown Timer works in Background https://navinkumar0118.medium.com/flutter-countdown-timer-works-in-background-f87488b0ba4c#:~:text=To%20run%20the%20timer%20on,on%20both%20native%20side%20classes. – Antonin Liehn Aug 30 '23 at 12:16