Skip to content

Flutter animation (Dart) ​

Flutter animates with retained, per-State controller objects: an AnimationController owns a Ticker that the SchedulerBinding calls once per frame in a dedicated transient-callback phase before build, the controller samples a Simulation at the elapsed time, and listeners turn the new value into setState, markNeedsLayout or a composited-layer update. Implicit widgets (AnimatedContainer, TweenAnimationBuilder) hide the controller inside their State; everything else, from Hero flights to AnimatedList removals, is built from the same three parts.

FieldValue
LanguageDart 3.13 (the SDK bundled with the surveyed release)
LicenseBSD-3-Clause (LICENSE)
Repositoryflutter/flutter: packages/flutter/lib/src/animation, scheduler, physics, widgets; tests in packages/flutter_test
DocumentationIntroduction to animations (docs.flutter.dev, "last updated on 2026-11-23") · Implicit animations · Hero animations · API docs in the source comments cited below
Categoryexplicit, imperative controllers (AnimationController) over a framework frame clock; implicit widgets layered on top; a pull-based Animation listenable graph
Versions surveyedFlutter 3.47.4 (tag commit 9584c67, 2026-09-10), the same pin as the reactive-programming deep-dive
Animation state lives inState objects and RenderObjects: each AnimationController (value, status, Simulation, Ticker) is a field of a State that mixes in TickerProviderStateMixin, or of a render object such as RenderAnimatedSize

NOTE

This page covers animation only. The widget/element/render-object trees, dirty lists and the frame pipeline that animation plugs into are described in Flutter widgets, elements and render objects and not repeated here; layout itself is in Flutter layout. Vocabulary (model vs presentation value, closed form vs stepped integration, retargeting) follows the catalog's concepts. Every claim below was read at the pinned tag.


Overview ​

What it solves ​

Flutter's widgets are immutable descriptions rebuilt from state, so a value that changes continuously between two states must live somewhere that survives rebuilds and advances on its own. Flutter's answer is an explicit object, the AnimationController, created in initState, disposed in dispose, and driven by a Ticker the framework calls once per frame. The rest of the library makes that object composable (Tween, CurvedAnimation, Animation.drive) and hides it where possible (implicit widgets). The official docs name the two families it supports: "In a tween animation, the beginning and ending points are defined, as well as a timeline, and a curve that defines the timing and speed of the transition", and "In physics-based animation, motion is modeled to resemble real-world behavior" (Introduction to animations).

Design philosophy ​

  1. Animation is a phase of the frame, not a side effect. WidgetsBinding.drawFrame lists it first: "The animation phase: The [handleBeginFrame] method […] invokes all the transient frame callbacks registered with [scheduleFrameCallback], in registration order. This includes all the [Ticker] instances that are driving [AnimationController] objects, which means all of the active [Animation] objects tick at this point" (binding.dart). Every animation in a frame therefore sees the same timestamp, and build, layout and paint see the ticked values.
  2. A controller is just a Simulation sampled by a Ticker. Duration-and-curve motion is an internal _InterpolationSimulation; fling is a SpringSimulation; animateWith accepts any Simulation (animation_controller.dart). A Simulation is a function of time: "In principle, simulations can be stateless, and thus can be queried with arbitrary times" (simulation.dart).
  3. Values are pulled, not pushed. Animatable.evaluate is transform(animation.value), and CurvedAnimation.value applies its curve on read (tween.dart, animations.dart). A chain controller → CurvedAnimation → Tween stores no intermediate values; only the controller holds state.
  4. The provider controls time; the consumer controls motion. "By convention, the [start] and [stop] methods are used by the ticker's consumer (for example, an [AnimationController]), and the [muted] property is controlled by the [TickerProvider] that created the ticker" (ticker.dart). That split lets TickerMode silence a whole subtree without the animations knowing.

How it works ​

Ticker and the transient-callback phase ​

SchedulerBinding.scheduleFrameCallback requests a frame and stores the callback in _transientCallbacks (source). handleBeginFrame computes _currentFrameTimeStamp = _adjustForEpoch(rawTimeStamp), enters SchedulerPhase.transientCallbacks, swaps the callback map for an empty one and invokes each callback with that one timestamp (source); the phases are idle → transientCallbacks → midFrameMicrotasks → persistentCallbacks (build/layout/paint) → postFrameCallbacks (SchedulerPhase).

A Ticker is a self-rescheduling transient callback. start() records _startTime = currentFrameTimeStamp if called mid-frame, otherwise the first tick sets it; _tick calls _onTick(timeStamp - _startTime!) and re-registers itself while shouldScheduleTick (!muted && isActive && !scheduled) holds (start, _tick). Callbacks therefore receive elapsed time since start, not wall time. A muted ticker "can still run, but the callback will not be called" (muted).

TickerProvider.createTicker is the only way to get one (source). SingleTickerProviderStateMixin/TickerProviderStateMixin vend tickers bound to a State, mute them from the inherited TickerMode, and assert at dispose that none is still active ("was disposed with an active Ticker", source).

AnimationController ​

The controller holds _value, _status, _direction, the current _simulation and the Ticker it got from vsync.createTicker(_tick) (constructor). Each tick evaluates the simulation at elapsed seconds, clamps to [lowerBound, upperBound], stops when isDone, and notifies (_tick):

dart
// packages/flutter/lib/src/animation/animation_controller.dart — _tick
void _tick(Duration elapsed) {
  _lastElapsedDuration = elapsed;
  final double elapsedInSeconds =
      elapsed.inMicroseconds.toDouble() / Duration.microsecondsPerSecond;
  _value = clampDouble(_simulation!.x(elapsedInSeconds), lowerBound, upperBound);
  if (_simulation!.isDone(elapsedInSeconds)) {
    _status = (_direction == _AnimationDirection.forward)
        ? AnimationStatus.completed
        : AnimationStatus.dismissed;
    stop(canceled: false);
  }
  notifyListeners();
  _checkStatusChanged();
}

forward, reverse and animateTo all route to _animateToInternal, which scales the duration by the remaining fraction of the range, calls stop(), and starts a fresh _InterpolationSimulation(_value, target, duration, curve, scale) (source). fling builds a SpringSimulation from value with the given velocity (source); animateWith(simulation) takes any simulation (source). Every start returns a TickerFuture, and a superseded one is cancelled rather than completed (stop). velocity is _simulation!.dx(elapsed) while animating and 0.0 otherwise (source).

Tween, Curve, CurvedAnimation ​

Animatable<T>.transform(double t) is the interpolation; evaluate(animation) and animate(parent) bind it to an Animation<double> (tween.dart). Tween<T> lerps begin/end (source); typed subclasses (ColorTween, RectTween, EdgeInsetsGeometryTween, DecorationTween) live beside the widgets that use them (implicit_animations.dart). Curve is a ParametricCurve<double>; Cubic is a CSS-style Bézier (Curves.easeInOut is Cubic(0.42, 0.0, 0.58, 1.0)), with Interval, Threshold and Curves constants alongside (curves.dart). CurvedAnimation applies curve, or reverseCurve while the parent runs in reverse, on each read of value (source).

Simulations and springs ​

Simulation exposes x(t), dx(t) and isDone(t) (source). SpringSimulation(spring, start, end, velocity) solves the damped oscillator in closed form (critically, under- or over-damped _SpringSolution) and is done when displacement and velocity are within tolerance (source). SpringDescription takes mass, stiffness, damping; withDampingRatio(mass, stiffness, ratio) derives damping = ratio · 2√(mass·stiffness); withDurationAndBounce(duration, bounce) "produces the same result as SwiftUI's spring(duration:bounce:blendDuration:) animation" (source). Scrolling is the main consumer: BallisticScrollActivity drives an AnimationController.unbounded(...).animateWith(simulation) (source).

Implicit animation: ImplicitlyAnimatedWidget and TweenAnimationBuilder ​

"Widgets of this type will not animate when they are first added to the widget tree. Rather, when they are rebuilt with different values, they will respond to those changes by animating the changes over a specified [duration]" (ImplicitlyAnimatedWidget). The State owns a controller and one tween per animated property, visited by the subclass's forEachTween. On every didUpdateWidget, if any target differs from its tween's end, each tween's begin becomes its current evaluated value and the controller restarts from zero (didUpdateWidget):

dart
// packages/flutter/lib/src/widgets/implicit_animations.dart — ImplicitlyAnimatedWidgetState
controller.duration = widget.duration;
if (_constructTweens()) {
  forEachTween((Tween<dynamic>? tween, dynamic targetValue, TweenConstructor<dynamic> constructor) {
    return tween
      ?..begin = tween.evaluate(_animation)
      ..end = targetValue;
  });
  controller.forward(from: 0.0);
  didUpdateTweens();
}

Two base states set the cost. AnimatedWidgetBaseState adds controller.addListener(() => setState(...)), so AnimatedContainer, AnimatedPadding and AnimatedAlign rebuild their subtree every tick (source). ImplicitlyAnimatedWidgetState alone does not: AnimatedOpacity builds a FadeTransition once, driven by animation.drive(tween) (source).

TweenAnimationBuilder exposes the same machinery to app code: "The new animation runs from the current animation value (which may be [Tween.end] of the old [tween], if that animation completed) to [Tween.end] of the new [tween]" (source); its forEachTween passes widget.tween.end as the target to the shared retarget logic (source).

AnimatedSwitcher and AnimatedList ​

AnimatedSwitcher compares the new child with the current one by Widget.canUpdate (type and key). On a change it moves the current _ChildEntry (widget, controller, transition) into _outgoingEntries, calls controller.reverse() on it, and creates a new entry that runs forward(); a status listener removes an outgoing entry with setState when its animation is dismissed (didUpdateWidget, _newEntry). build hands the current transition and every outgoing one to layoutBuilder, by default a Stack (source, defaultLayoutBuilder). The outgoing child is the old widget description, kept and rebuilt every frame under a KeyedSubtree; its element and state stay mounted.

AnimatedList is imperative. The app mutates its own list and then calls AnimatedListState.insertItem(index) or removeItem(index, builder) through a GlobalKey (removeItem). A removal records an _ActiveItem.outgoing(controller, itemIndex, builder), reverses the controller, and only when it completes decrements _itemsCount; until then _itemBuilder calls the removed-item builder for that index instead of itemBuilder (_itemBuilder, AnimatedRemovedItemBuilder). The removed item is rebuilt from whatever the closure captured. There is no move or reorder animation.

Hero ​

A HeroController (a NavigatorObserver) pairs heroes with equal tag in the outgoing and incoming routes. Unless a pop gesture can use already-laid-out geometry, it puts the incoming route offstage for a frame and starts the flight from a post-frame callback: "Once this frame completes, we'll know where the heroes in the to route are going to end up" (_maybeStartHeroTransition). _HeroFlightManifest measures each hero's RenderBox with getTransformTo into its route's coordinate space (source). _HeroFlight.start builds a RectTween(fromHeroLocation, toHeroLocation), swaps both heroes for size-preserving placeholders, and inserts an OverlayEntry that positions the shuttle with Positioned from heroRectTween.evaluate(_proxyAnimation) each frame (start, _buildOverlay). Each tick re-reads the destination's position and retargets the tween's end if it moved (onTick); a push or pop mid-flight calls divert, which starts the new tween at heroRectTween.evaluate(_proxyAnimation) (source). The docs set the limits: "If the [Hero] isn't axis aligned, this is going to fail in a rather ugly fashion. Don't rotate your heroes!" (source).

Layout-driven animation: RenderAnimatedSize ​

AnimatedSize is implemented in the render tree. RenderAnimatedSize.performLayout lays out its child, then a four-state machine (start, stable, changed, unstable) decides whether to animate: a child size change while stable sets _sizeTween.begin = size (its own current size) and end = child.size and restarts; a child that changes size two frames running is tracked tightly instead of chased (states, performLayout, _layoutStable). The controller's listener calls markNeedsLayout() (source).

timeDilation, TickerMode and reduced motion ​

timeDilation is a global that divides elapsed raw time in _adjustForEpoch; setting it calls resetEpoch so time stays monotonic (timeDilation, _adjustForEpoch). TickerMode(enabled: false) mutes every widget-aware ticker below it: "Animations driven by such tickers are not paused, they just don't call their callbacks. Time still elapses" (source). Each OverlayEntry wraps its content in TickerMode(enabled: widget.tickerEnabled), and OverlayState.build passes tickerEnabled: false to every entry below the topmost opaque one that maintainStates, which is how routes covered by an opaque route stop animating (_OverlayEntryWidget, OverlayState.build).

Reduced motion is read from the engine, not from the widget tree. AnimationBehavior.normal consults SemanticsBinding.instance.disableAnimations (source), and when it is set _animateToInternal runs the curve at 5 % of its duration: "the common pattern of an eternally repeating animation might cause an endless loop if it weren't delayed for at least one frame. Instead, it's run at 5% of the normal duration" (source); fling multiplies velocity by 200 instead (source). MediaQueryData.disableAnimations mirrors the flag but "cannot be overridden using [MediaQuery]" for framework animations, and "On iOS, reduced motion is exposed separately via [dart:ui.AccessibilityFeatures.reduceMotion] and does not set this flag" (media_query.dart).

Testing: FakeAsync and pump(duration) ​

AutomatedTestWidgetsFlutterBinding runs each test inside a FakeAsync zone (source). tester.pump(duration) calls _currentFakeAsync!.elapse(duration) and then, if a frame is scheduled, exactly one handleBeginFrame(clock.now()) and handleDrawFrame() (pump). One pump(const Duration(milliseconds: 150)) therefore samples every animation at t = 150 ms with no intermediate frames. pumpAndSettle pumps in 100 ms steps while (binding.hasScheduledFrame) and throws on timeout (source); hasRunningAnimations is transientCallbackCount > 0 (source). After a test, a pending fake timer is an assertion failure (_verifyInvariants).


Analysis ​

Where animation state lives ​

In ordinary objects owned by retained nodes: AnimationController fields of a State (reached through the element tree, the reactive-programming deep-dive), or of a RenderObject (RenderAnimatedSize). Identity is therefore element identity: a keyed or same-type rebuild keeps the controller, and a type or key change disposes it. Values downstream of the controller (CurvedAnimation, Tween) are stateless views. There is no central animation store and no model/presentation split at the framework level: a widget's field holds the target and the controller holds the presentation value, and app code wires one to the other.

Declaring an animation ​

Both styles exist and the explicit one is primary. Explicit: the app creates a controller with vsync: this, calls forward/animateTo/animateWith, and feeds controller.drive(tween) into an AnimatedWidget (FadeTransition, SlideTransition) or AnimatedBuilder. Implicit: AnimatedContainer(duration:, curve:, ...) and TweenAnimationBuilder(tween:, ...) animate when a rebuild passes a different target; the declaration is the target plus a duration and curve, with no velocity or spring option (ImplicitlyAnimatedWidget). Implicit widgets are a thin, fixed policy over the explicit API, not a separate engine.

Time and the clock ​

The SchedulerBinding owns the clock. The engine supplies a vsync timestamp, _adjustForEpoch applies timeDilation, and that one currentFrameTimeStamp is handed to every transient callback in a frame (handleBeginFrame). Tickers convert it to elapsed-since-start; controllers evaluate a Simulation at that elapsed time, so the motion is a closed-form function of frame time, not a stepped integration. Frames are frame ticks only: there is no document or scroll timeline (scroll-linked effects read ScrollPosition.pixels in build or paint). Muted time keeps elapsing (TickerMode), so a resumed ticker jumps forward rather than pausing.

Interruption and retargeting ​

There is one rule, applied by every start method: stop() the current simulation and start a new one from the current value (_animateToInternal, animateWith). Value is continuous; velocity is not carried by animateTo or by implicit widgets. _InterpolationSimulation has no initial-velocity term, and ImplicitlyAnimatedWidgetState restarts with forward(from: 0.0) over the full duration from the new begin (didUpdateWidget), so a rapid sequence of retargets never finishes and shows a velocity kink at each change. Preserving momentum is opt-in: read controller.velocity and pass it to a SpringSimulation via animateWith, as scrolling and fling do. There is no additive composition; two controllers writing one property must be combined by app code (AnimationMean, AnimationMax combine Animations, not targets, animations.dart). Hero.divert is the most complete retarget in the framework: it restarts from the evaluated in-flight rect toward the new destination (source).

Curves and springs ​

Duration-plus-curve is the default everywhere (Curves.*, Cubic, Interval). Springs are Simulations parametrised physically (mass, stiffness, damping), by ratio (withDampingRatio), or perceptually (withDurationAndBounce, matching SwiftUI) (source). A spring is only reachable through the explicit API (animateWith, fling); no implicit widget takes one. A spring's end is decided by tolerance (distance and velocity), not a duration (isDone), and fling asserts that its spring is not underdamped (source).

Layout animation ​

Flutter has no general layout-transition mechanism; each widget picks a phase.

MechanismRuns inNeeds previous geometry?Source
AnimatedContainer, AnimatedPadding, …build: setState per tick, then normal layoutno; interpolates the widget's own previous parameters (begin = current)AnimatedWidgetBaseState
AnimatedSize (RenderAnimatedSize)layout: performLayout measures the child, then animates own sizeyes, its own last laid-out size becomes begin_layoutStable
FadeTransition, AnimatedOpacitycompositing: markNeedsCompositedLayerUpdate, no rebuild or repaintno_updateOpacity, doc
Herobuild in an Overlay per tick, from rects measured after layoutyes, both: source rect from the current route, destination after an offstage layout frame_maybeStartHeroTransition

So the geometry-animating mechanisms that need two layouts get the second one either by owning a render object that remembers its last size (RenderAnimatedSize), or by delaying the start by a frame and reading RenderBox positions from a post-frame callback (Hero). Nothing animates position changes of ordinary children (no FLIP for reorders); AnimatedList has no move (removeItem). Paint- and compositor-only animation is available when the value is pushed straight into a render object (RenderAnimatedOpacity listens to its Animation directly), which skips build and layout.

Enter and exit ​

Exit is done by keeping the old widget description alive in a State, not by snapshotting pixels. AnimatedSwitcher keeps outgoing _ChildEntrys, each with its old widgetChild and controller, and builds them every frame until their reverse animation is dismissed (source). AnimatedList keeps an outgoing _ActiveItem with the app's removed-item builder until its controller completes (source). Hero replaces the source hero with a placeholder and flies a shuttle widget in an OverlayEntry, removed in _performAnimationUpdate when the animation stops (source). In every case the departing content is still a live subtree, rebuilt, laid out and painted, and it must be described by data the app no longer holds (AnimatedList's builder closure captures it). Enter has no dedicated API: an implicit widget does not animate on first build (ImplicitlyAnimatedWidget), so enter is spelled either with TweenAnimationBuilder (whose first build runs begin → end, source) or with an explicit controller started in initState.

Scheduling, reduced motion and testing ​

Frames are requested only while something is ticking: Ticker.scheduleTick calls scheduleFrame and re-registers only while active and unmuted (source), and a completed simulation stops its ticker (_tick). TickerMode and route offstaging cut work for invisible subtrees. Reduced motion is global and automatic but blunt: Android's "Remove animations" (AccessibilityFeatures.disableAnimations) shrinks every AnimationBehavior.normal controller to 5 % of its duration, cannot be overridden per subtree, and iOS's separate reduceMotion is not honoured unless app code reads it (media_query.dart). Tests get a fully virtual clock: FakeAsync plus pump(duration) produce one frame at an exact time, so animation states are assertable at arbitrary instants and tests run in microseconds (pump).

Lessons for sparkles:ui ​

  • A dedicated animation phase before build is the right shape for a pure build. Flutter samples every animation once, at one timestamp, before any build runs. A sparkles host that advances store-held animation phases at FrameStart and lets components read the committed values matches this exactly, with no ticker objects in components (baseline).
  • Closed-form simulations make time a parameter. Because Simulation.x(t) is a function of elapsed time, Flutter's controllers need no per-frame state beyond the start time, which is what makes pump(duration) and timeDilation trivial. A store entry of (start time, from, to, velocity, spec) evaluated at the frame time is @nogc plain data with the same property.
  • Retarget-from-current-value without velocity is the failure case to avoid. ImplicitlyAnimatedWidget restarts the full duration from the current value and drops velocity; Compose and SwiftUI carry it (Compose). A store that keeps velocity alongside the value can retarget springs continuously at no extra cost.
  • For UI-Q9, Flutter puts geometry animation where the previous geometry already is. RenderAnimatedSize animates in layout because it holds last frame's size; Hero waits a frame and reads RenderBox rects post-layout. A sparkles component should not need to read last frame's rect to animate a resize: the host can interpolate between the committed rect and this frame's laid-out rect after layout, as RenderAnimatedSize does inside layout. See UI-Q9 (PR #775).
  • For UI-Q10, Flutter's exits retain descriptions, not pixels, and that pushes the burden onto the app. AnimatedList.removeItem makes the app supply a builder for an item it has already deleted. A store-driven closing state that repaints the element's last committed subtree removes that burden; a retained draw list (Compose's lazy-list approach, Compose) is the cheaper variant when the subtree need not stay live. See UI-Q10 (PR #775).
  • Reduced motion belongs to the animation layer, but per subtree. Flutter's 5 % rule is automatic and sound for loops, yet the flag cannot be scoped or overridden; sparkles can apply the same substitution in the host while still letting a component ask for "essential motion" (AnimationBehavior.preserve).

Strengths ​

  • One clock, one phase: every animation in a frame sees the same timestamp, and build/layout/paint see ticked values (drawFrame).
  • Simulation is a small, general, closed-form interface; tweens, springs, friction and scroll physics all fit it.
  • A fully virtual test clock with exact-time sampling (FakeAsync, pump(duration)), plus a dev-time timeDilation.
  • Cheap paths exist below build: FadeTransition/RenderAnimatedOpacity update a composited layer without rebuilding or repainting children.
  • TickerMode silences offstage subtrees without the animations' cooperation.

Weaknesses ​

  • Controllers are manual resources: vsync, initState, dispose, and a debug assertion if a ticker outlives its State (source).
  • Implicit animations restart the full duration and drop velocity on every retarget (source); springs are unavailable to them.
  • No general layout animation: no reorder/FLIP, Hero only across routes and only for axis-aligned rects, AnimatedSize only for its own box.
  • Exit animations require keeping or reconstructing the departing widget (AnimatedList's removed-item builder, AnimatedSwitcher's retained child).
  • Reduced motion cannot be scoped or overridden per subtree, and iOS's flag is separate.

Key design decisions and trade-offs ​

DecisionRationaleTrade-off
Animation runs in a transient-callback phase before buildone timestamp per frame; build/layout/paint see consistent ticked valuesan animation cannot react to this frame's layout until the next frame
AnimationController is an explicit object owned by a Statefull control: start, stop, reverse, fling, status, futureslifecycle boilerplate (vsync, dispose); state hidden in widget internals
Motion is a Simulation evaluated at elapsed timeclosed form, seekable, trivially testable and dilatablevelocity continuity across restarts is not automatic
Animation values are pulled through Tween/CurvedAnimationcomposition without intermediate stateevery read recomputes; listeners must be wired per consumer
Implicit widgets restart from the current value, full durationsimple, no velocity bookkeepingvisible kinks and never-finishing motion under rapid retargeting
Exit keeps the old widget alive in an owning Statethe departing subtree stays interactive-capable and re-layoutablethe app must preserve or rebuild data for content it has already removed
Hero waits one frame and flies in an Overlayboth routes' geometry known; shuttle escapes route clippingone-frame start latency; axis-aligned rects only
Reduced motion scales controllers to 5 %, read from the engineautomatic, safe for repeating animationsnot overridable or scoped; iOS reduce-motion separate

Sources ​