Home > OS >  What happens to Flutter Ticker if the UI misses frames due to bad performances?
What happens to Flutter Ticker if the UI misses frames due to bad performances?

Time:11-06

I read on the the Ticker class documentation that:

"Ticker class calls its callback once per animation frame."

I am using createTicker(TickerCallback onTick) to implement a stopwatch. So I need the elapsed variable passed to the TickerCallback to be extremely precise (i.e. i need that after 5 seconds, the value of elapsed is exactly 5 seconds).

Now my question is: what happens if I have a sluggish UI very badly coded and that misses a lot of frame due to bad optimization? I can think of 2 cases:

  1. The time of the stopwatch gets updated not at 60fps (because of my bad coding) but once it gets updated, the time being displayed is correct
  2. The time displayed is wrong
  3. Other?

Which is the case? And why (most importantly)? Also, considering the above, is it adviceable to use ticker for a stopwatch? Thanks

CodePudding user response:

To answer your question(s):

1.The time of the stopwatch gets updated not at 60fps (because of my bad coding) but once it gets updated, the time being displayed is correct.

If phone works at 120 fps, does that mean it will forward time :)

Flutter aims to provide 60 frames per second (fps) performance, or 120 fps performance on devices capable of 120Hz updates. For 60fps, frames need to render approximately every 16ms. Jank occurs when the UI doesn't render smoothly.

So you may use ticker, and even if animation is sluggish, still it will display right time. Like on let say we have some delays on frames 500, they will be delays of animation not the time passed. Like on second 3 we have 1 second delay we will have 5 after that, it updates the screen, but timer will continue.

Also, considering the above, is it adviceable to use ticker for a stopwatch?

It is. At worst case you will have drop frames, jumping seconds but timer will be exact.

  • Related