How is AnimationController different from Timer?

Technology CommunityCategory: FlutterHow is AnimationController different from Timer?
VietMX Staff asked 3 years ago
  • *Timer is unrelated to Flutter, and is just a timer like you’d fine in any other language.
  • On the other hand, AnimationController (and Ticker, its equivalent of Timer) is Flutter specific.
  • The difference with a Timer is that, by using AnimationController, the “ticker” can be muted, slowed, or mocked.

As such, using AnimationController we have a few benefits:

  • if the associated widget isn’t visible, the animation is paused (that’s what that vsync arg is used for)
  • we get access to a “slow animations” devtool which makes the seconds slower for animations only
  • tests can “mock” these timers. As such, if an animation last 3 seconds, a test can simulate the entire animation without having to actually wait for 3 seconds.