text stringlengths 1 372 |
|---|
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 |
the primary building block of the animation system is the |
animation class. an animation represents a value |
of a specific type that can change over the lifetime of |
the animation. most widgets that perform an animation |
receive an animation object as a parameter, |
from which they read the current value of the animation |
and to which they listen for changes to that value. |
<topic_end> |
<topic_start> |
addListener |
whenever the animation’s value changes, |
the animation notifies all the listeners added with |
addListener. typically, a state |
object that listens to an animation calls |
setState on itself in its listener callback |
to notify the widget system that it needs to |
rebuild with the new value of the animation. |
this pattern is so common that there are two widgets |
that help widgets rebuild when animations change value: |
AnimatedWidget and AnimatedBuilder. |
the first, AnimatedWidget, is most useful for |
stateless animated widgets. to use AnimatedWidget, |
simply subclass it and implement the build function. |
the second, AnimatedBuilder, is useful for more complex widgets |
that wish to include an animation as part of a larger build function. |
to use AnimatedBuilder, simply construct the widget |
and pass it a builder function. |
<topic_end> |
<topic_start> |
addStatusListener |
animations also provide an AnimationStatus, |
which indicates how the animation will evolve over time. |
whenever the animation’s status changes, |
the animation notifies all the listeners added with |
addStatusListener. typically, animations start |
out in the dismissed status, which means they’re |
at the beginning of their range. for example, |
animations that progress from 0.0 to 1.0 |
will be dismissed when their value is 0.0. |
an animation might then run forward (from 0.0 to 1.0) |
or perhaps in reverse (from 1.0 to 0.0). |
eventually, if the animation reaches the end of its range |
(1.0), the animation reaches the completed status. |
<topic_end> |
<topic_start> |
AnimationController |
to create an animation, first create an AnimationController. |
as well as being an animation itself, an AnimationController |
lets you control the animation. for example, |
you can tell the controller to play the animation |
forward or stop the animation. |
you can also fling animations, |
which uses a physical simulation, such as a spring, |
to drive the animation. |
once you’ve created an animation controller, |
you can start building other animations based on it. |
for example, you can create a ReverseAnimation |
that mirrors the original animation but runs in the |
opposite direction (from 1.0 to 0.0). |
similarly, you can create a CurvedAnimation |
whose value is adjusted by a curve. |
<topic_end> |
<topic_start> |
tweens |
to animate beyond the 0.0 to 1.0 interval, you can use a |
Tween<T>, which interpolates between its |
begin and end values. many types have specific |
tween subclasses that provide type-specific interpolation. |
for example, ColorTween interpolates between colors and |
RectTween interpolates between rects. |
you can define your own interpolations by creating |
your own subclass of tween and overriding its |
lerp function. |
by itself, a tween just defines how to interpolate |
between two values. to get a concrete value for the |
current frame of an animation, you also need an |
animation to determine the current state. |
there are two ways to combine a tween |
with an animation to get a concrete value: |
you can evaluate the tween at the current |
value of an animation. this approach is most useful |
for widgets that are already listening to the animation and hence |
rebuilding whenever the animation changes value. |
you can animate the tween based on the animation. |
rather than returning a single value, the animate function |
returns a new animation that incorporates the tween. |
this approach is most useful when you want to give the |
newly created animation to another widget, |
which can then read the current value that incorporates |
the tween as well as listen for changes to the value. |
<topic_end> |
<topic_start> |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.