Back to results for “Animations”
Flutter › Flutter Animations Basics

How does a Tween work together with an AnimationController to actually define the specific range of values, such as a color or a position, that an animation should smoothly transition between?

Intermediate

Answer

A Tween, short for in between, defines the specific starting and ending values that an animation should smoothly interpolate between as the underlying AnimationController's progress value moves from zero to one, and calling the Tween's animate method, passing in the AnimationController, produces an Animation object that continuously computes and provides the correctly interpolated current value at any given point during that animation's overall progress, letting you animate not just simple numeric values but also more complex types like Color or Offset, provided a suitable specialized Tween subclass exists for that specific type.
final colorAnimation = ColorTween(begin: Colors.blue, end: Colors.red)
  .animate(controller);
Real-world example A button press feedback animation smoothly transitions its background color from blue to red using a ColorTween driven by an AnimationController, providing clear, satisfying visual feedback that a specific action has genuinely been registered.

Common follow-ups: What is the difference between a regular Tween and a specialized ColorTween or a CurveTween?;Can a single AnimationController drive several separate different Tween animations all at the same time?