text
stringlengths
1
474
<topic_start>
Other resources
Learn more about Flutter animations at the following links:Animation samples from the Sample app catalog.Animation recipes from the Flutter cookbook.Animation videos from the Flutter YouTube channel.Animations: overview
A look at some of the major classes in the
animations library, and Flutter’s animation architecture.Animation and motion widgets
A catalog of some of the animation widgets
provided in the Flutter APIs.The animation library in the Flutter API documentation
The animation API for the Flutter framework. This link
takes you to a technical overview page for the library.
<topic_end>
<topic_start>Animations tutorial
<topic_end>
<topic_start>What you'll learn
This tutorial shows you how to build explicit animations in Flutter.
After introducing some of the essential concepts, classes,
and methods in the animation library, it walks you through 5
animation examples. The examples build on each other,
introducing you to different aspects of the animation library.The Flutter SDK also provides built-in explicit animations,
such as FadeTransition, SizeTransition,
and SlideTransition. These simple animations are
triggered by setting a beginning and ending point.
They are simpler to implement
than custom explicit animations, which are described here.<topic_end>
<topic_start>
Essential animation concepts and classes
<topic_end>
<topic_start>What's the point?
The animation system in Flutter is based on typed
Animation objects. Widgets can either incorporate
these animations in their build functions directly by
reading their current value and listening to their state
changes or they can use the animations as the basis of
more elaborate animations that they pass along to
other widgets.<topic_end>
<topic_start>
Animation<double>
In Flutter, an Animation object knows nothing about what
is onscreen. An Animation is an abstract class that
understands its current value and its state (completed or dismissed).
One of the more commonly used animation types is Animation<double>.An Animation object sequentially generates
interpolated numbers between two values over a certain duration.
The output of an Animation object might be linear,
a curve, a step function, or any other mapping you can devise.
Depending on how the Animation object is controlled,
it could run in reverse, or even switch directions in the
middle.Animations can also interpolate types other than double, such as
Animation<Color> or Animation<Size>.An Animation object has state. Its current value is
always available in the .value member.An Animation object knows nothing about rendering or
build() functions.<topic_end>
<topic_start>
Curved­Animation
A CurvedAnimation defines the animation’s progress
as a non-linear curve.
<code_start>animation = CurvedAnimation(parent: controller, curve: Curves.easeIn);<code_end>
info Note
The Curves class defines many commonly used curves,
or you can create your own. For example:Browse the Curves documentation for a complete listing
(with visual previews) of the Curves constants that ship with Flutter.CurvedAnimation and AnimationController (described in the next section)
are both of type Animation<double>, so you can pass them interchangeably.
The CurvedAnimation wraps the object it’s modifying—you
don’t subclass AnimationController to implement a curve.<topic_end>
<topic_start>
Animation­Controller
AnimationController is a special Animation
object that generates a new value whenever the hardware
is ready for a new frame. By default,
an AnimationController linearly produces the numbers
from 0.0 to 1.0 during a given duration.
For example, this code creates an Animation object,
but does not start it running:
<code_start>controller =
AnimationController(duration: const Duration(seconds: 2), vsync: this);<code_end>
AnimationController derives from Animation<double>, so it can be used
wherever an Animation object is needed. However, the AnimationController
has additional methods to control the animation. For example, you start
an animation with the .forward() method. The generation of numbers is
tied to the screen refresh, so typically 60 numbers are generated per
second. After each number is generated, each Animation object calls the
attached Listener objects. To create a custom display list for each
child, see RepaintBoundary.When creating an AnimationController, you pass it a vsync argument.
The presence of vsync prevents offscreen animations from consuming
unnecessary resources.
You can use your stateful object as the vsync by adding
SingleTickerProviderStateMixin to the class definition.
You can see an example of this in animate1 on GitHub.info Note
In some cases, a position might exceed the AnimationController’s
0.0-1.0 range. For example, the fling() function
allows you to provide velocity, force, and position
(via the Force object). The position can be anything and
so can be outside of the 0.0 to 1.0 range.A CurvedAnimation can also exceed the 0.0 to 1.0 range,
even if the AnimationController doesn’t.
Depending on the curve selected, the output of
the CurvedAnimation can have a wider range than the input.
For example, elastic curves such as Curves.elasticIn
significantly overshoots or undershoots the default range.<topic_end>
<topic_start>
Tween
By default, the AnimationController object ranges from 0.0 to 1.0.
If you need a different range or a different data type, you can use a
Tween to configure an animation to interpolate to a