Tickers, Timers, Tests, and FPS #131357
Labels
a: tests
"flutter test", flutter_test, or one of our tests
framework
flutter/packages/flutter repository. See also f: labels.
P2
Important issues not at the top of the work list
team-framework
Owned by Framework team
triaged-framework
Triaged by Framework team
In Flutter widgets,
Timer
s are a problem because they aren't controlled by Flutter's test runner. Instead, Flutter providesTicker
s, which hook into the Flutter pipeline, and therefore they can be controlled in tests. Generally speaking, anyTimer
behavior will produce unpredictable test results and therefore shouldn't be used in widgets.However, there seems to be an issue with relying on
Ticker
s for time tracking, too. Namely,Ticker
s seem to continuously schedule new frames, and force Flutter into a full FPS execution, which, at best, is a big waste of device energy.Here's a real-world example. In Super Editor, we flash a text caret on and off every 0.5 seconds. To do this, we could use a
Timer
, but as mentioned above,Timer
s don't play well with tests. Therefore, we register aTicker
and observe the passage of time. When we see 0.5 seconds pass, we show or hide the caret.Apparently, by using a
Ticker
, Flutter constantly schedules frames, yielding 58 unnecessary frames per second. Moreover, this constant frame scheduling prevents mobile devices from entering low-frame-rate mode.Is there a canonical solution to this
Ticker
problem? If not, I think Flutter needs a way to handle the passage of time, which integrates with tests, and also doesn't schedule unnecessary frames.The text was updated successfully, but these errors were encountered: