Strange behaviour of Timer.periodic(...)

1,024 views
Skip to first unread message

Simone Giacomelli

unread,
Jun 12, 2017, 6:28:13 AM6/12/17
to Flutter Dev
Hi guys,
  I developed a Flutter application that basically is a count down timer.
It is based on the Pomodoro Technique.

I want to report a strange behaviour of Timer.periodic() that sadly I cannot repro (hence I did not open a github issue) 

In my app, I have a nice "Start" button that start's a count down. You can see below the code I use to start a timer.
I'm using this app daily for about 1 and half month. Each day I use it from ten to twenty times.

This issue arose only few times, let's say 6 or 7 times.

It looks like the timer doesn't fire. Today I was more prepared than before: previously I scattered around the code many logs statements.

So I pluged in the usb cable with the issue live on my phone and typed "flutter logs" and then clicked "Cancel" and then "Start" again.
And there was no ticking log... So I started to google around, check the github issues, stack overflow... but I found nothing.

Meanwhile, I looked again on my phone screen and the countdown timer was counting again! 
Infact, if you look the logs with the issue, notice that the timer jumps from "25:00" to "16:34"! It looks like after some 9 minutes, the timer started to tick!
Weird...

Anyway, I don't have any POC... or minimal test set... I just dropped few lines in the case somebody else bump into this...

Thank you for your great work guys!

cheers
Simone 

session.start = new DateTime.now();
//...
_timer?.cancel();
_timer = new Timer.periodic(new Duration(milliseconds: 100), (Timer t) {
  //...
});


------flutter logs (with the issue)
I/flutter (  509): setDuration 25
I/flutter (  509): changing from 25:00 to 16:34
I/flutter (  509): changing from 16:34 to 16:33
I/flutter (  509): changing from 16:33 to 16:32
I/flutter (  509): changing from 16:32 to 16:31
I/flutter (  509): changing from 16:31 to 16:30

------flutter logs (without the issue)
I/flutter (  509): setDuration 25
I/flutter (  509): changing from 25:00 to 24:59
I/flutter (  509): changing from 24:59 to 24:58
I/flutter (  509): changing from 24:58 to 24:57
etc etc

Collin Jackson

unread,
Jun 13, 2017, 1:54:56 PM6/13/17
to Flutter Dev
It's hard for me to debug this without seeing the rest of your code, but I would recommend using an AnimationController with an IntTween if you want a timer that fires once per second.

Here's an example that does that.


--
You received this message because you are subscribed to the Google Groups "Flutter Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Reply all
Reply to author
Forward
0 new messages