Answer
Overview
A Ticker in Flutter is an object that fires a callback once per frame (typically 60 times per second). It is the foundation of Flutter's animation system — every animation uses a Ticker under the hood.
How Ticker Works
textFrame 1 (0ms) → Ticker fires → AnimationController updates → Widget rebuilds Frame 2 (16ms) → Ticker fires → AnimationController updates → Widget rebuilds Frame 3 (32ms) → Ticker fires → AnimationController updates → Widget rebuilds ...
A Ticker sends the elapsed time since it started to its callback on every frame.
SingleTickerProviderStateMixin
The most common way to use a Ticker in Flutter — automatically provides a
text
vsynctext
AnimationControllerdartclass MyAnimatedWidget extends StatefulWidget { _MyAnimatedWidgetState createState() => _MyAnimatedWidgetState(); } class _MyAnimatedWidgetState extends State<MyAnimatedWidget> with SingleTickerProviderStateMixin { late AnimationController _controller; void initState() { super.initState(); _controller = AnimationController( vsync: this, // ← 'this' is the Ticker provider duration: Duration(seconds: 2), )..repeat(); // Loop forever } void dispose() { _controller.dispose(); // Always dispose! super.dispose(); } Widget build(BuildContext context) { return RotationTransition( turns: _controller, child: Icon(Icons.refresh, size: 48), ); } }
TickerProviderStateMixin (Multiple Animations)
When you need more than one AnimationController:
dartclass _MyState extends State<MyWidget> with TickerProviderStateMixin { // ← Note: no "Single" late AnimationController _controller1; late AnimationController _controller2; void initState() { super.initState(); _controller1 = AnimationController(vsync: this, duration: Duration(seconds: 1)); _controller2 = AnimationController(vsync: this, duration: Duration(milliseconds: 500)); } void dispose() { _controller1.dispose(); _controller2.dispose(); super.dispose(); } }
Ticker vs AnimationController
| Concept | Role |
|---|---|
| Ticker | Low-level: fires once per frame |
| AnimationController | High-level: uses Ticker to drive animation values |
| vsync | Connects AnimationController to a Ticker |
Why vsync Matters
text
vsyncdart// ✅ With vsync — animation pauses when off-screen AnimationController(vsync: this, duration: Duration(seconds: 1)) // ❌ Without vsync — animation keeps running even when not visible (bad!)
Summary: A
fires a callback every frame. UsetextTickerfor single animations andtextSingleTickerProviderStateMixinfor multiple animations. AlwaystextTickerProviderStateMixinyour controllers.textdispose()