Animation<T> class abstract

A value which might change over time, moving forward or backward.

An animation has a value (of type T) and a status. The value conceptually lies on some path, and the status indicates how the value is currently moving along the path: forward, backward, or stopped at the end or the beginning. The path may double back on itself (e.g., if the animation uses a curve that bounces), so even when the animation is conceptually moving forward the value might not change monotonically.

Consumers of the animation can listen for changes to either the value or the status, with addListener and addStatusListener. The listener callbacks are called during the "animation" phase of the pipeline, just prior to rebuilding widgets.

An animation might move forward or backward on its own as time passes (like the opacity of a button that fades over a fixed duration once the user touches it), or it might be driven by the user (like the position of a slider that the user can drag back and forth), or it might do both (like a switch that snaps into place when released, or a Dismissible that responds to drag and fling gestures, etc.). The behavior is normally controlled by method calls on some underlying AnimationController. When an animation is actively animating, it typically updates on each frame, driven by a Ticker.

Using animations

For simple animation effects, consider using one of the ImplicitlyAnimatedWidget subclasses, like AnimatedScale, AnimatedOpacity, and many others. When an ImplicitlyAnimatedWidget suffices, there is no need to work with Animation or the rest of the classes discussed in this section.

Otherwise, typically an animation originates with an AnimationController (which is itself an Animation<double>) created by a State that implements TickerProvider. Further animations might be derived from that animation by using e.g. Tween or CurvedAnimation. The animations might be used to configure an AnimatedWidget (using one of its many subclasses like FadeTransition), or their values might be used directly.

For example, the AnimationController may represent the abstract progress of the animation from 0.0 to 1.0; then a CurvedAnimation might apply an easing curve; and a SizeTween and ColorTween might each be applied to that to produce an Animation<Size> and an Animation<Color> that control a widget shrinking and changing color as the animation proceeds.

Performance considerations

Because the Animation keeps the same identity as the animation proceeds, it provides a convenient way for a StatefulWidget that orchestrates a complex animation to communicate the animation's progress to its various child widgets. Consider having higher-level widgets in the tree pass lower-level widgets the Animation itself, rather than its value, in order to avoid rebuilding the higher-level widgets on each frame even while the animation is active. If the leaf widgets also ignore value and pass the whole Animation object to a render object (like FadeTransition does), they too might be able to avoid rebuild and even relayout, so that the only work needed on each frame of the animation is to repaint.

See also:

Inheritance
Implemented types
Implementers

Constructors

Animation()
Abstract const constructor. This constructor enables subclasses to provide const constructors so that they can be used in const expressions.
const
Animation.fromValueListenable(ValueListenable<T> listenable, {ValueListenableTransformer<T>? transformer})
Create a new animation from a ValueListenable.
factory

Properties

hashCode int
The hash code for this object.
no setterinherited
isAnimating bool
Whether this animation is running in either direction.
no setter
isCompleted bool
Whether this animation is stopped at the end.
no setter
isDismissed bool
Whether this animation is stopped at the beginning.
no setter
isForwardOrCompleted bool
Whether the current aim of the animation is toward completion.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
status AnimationStatus
The current status of this animation.
no setter
value → T
The current value of the animation.
no setteroverride

Methods

addListener(VoidCallback listener) → void
Calls the listener every time the value of the animation changes.
override
addStatusListener(AnimationStatusListener listener) → void
Calls listener every time the status of the animation changes.
drive<U>(Animatable<U> child) Animation<U>
Chains a Tween (or CurveTween) to this Animation.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
removeListener(VoidCallback listener) → void
Stop calling the listener every time the value of the animation changes.
override
removeStatusListener(AnimationStatusListener listener) → void
Stops calling the listener every time the status of the animation changes.
toString() String
A string representation of this object.
override
toStringDetails() String
Provides a string describing the status of this object, but not including information about the object itself.

Operators

operator ==(Object other) bool
The equality operator.
inherited