The Animation<T> class

In Flutter, animations consist of status and a value with the T type. The animation status corresponds to its state (that is, if it's running or completed); its value corresponds to its current value, and it is intended to change during the animation execution.

Besides holding that information about the animation, this class exposes callbacks so other classes can know how the animations are running, and the animation's current status and value too.

An Animation<T> class instance is only responsible for holding and exposing those values. It does not know anything about visual feedback, what is drawn on screen, or how to draw it (that is, build() functions).

One of the most common kinds of animation you will see is the Animation<double> type representation, as double value can easily be used to manipulate any kind of values in a sense of proportional space.

The Animation class generates a sequence (not necessarily linear) of values between determined minimum and maximum values. This process is also known as interpolation and, as said before, this interpolation is not only linear—it can be defined as a step function or a curve. Flutter provides multiple functions and facilities for operating animations. They are as follows:

  • AnimationController: Despite what its name suggests, it is not used to control animation objects, but helps in the control task of itself, as it extends the Animation class and still is an animation.
  • CurvedAnimation: This is an animation that applies Curve to another animation.
  • Tween: This helps to create a linear interpolation between a beginning and ending value.

The Animation class exposes ways of accessing its state and value during a running cycle. Through status listeners, we can know when an animation begins, ends, or goes in the reverse direction. By using its addStatusListener() method, we can, for example, manipulate our widgets in response to animation start or end events. The same way, we can add value listeners with the addListener() method so we get notified every time the animation value changes, and we can rebuild our widgets by using setState() {}.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.197.123