In Flutter, an AnimationController
is a controller for an Animation
. It’s responsible for driving an animation, and it has methods for controlling the animation’s state, like forward
, reverse
, and stop
. It also has properties for accessing the current value of the animation, as well as the animation’s status and duration.
On the other hand, an Animation
is a value that changes over a given duration. It has a value at a specific point in time, and it can be used to drive the appearance of a widget. An Animation
doesn’t have any methods for controlling its state, it just represents the value of the animation at a given point in time.
Here’s an example of how you might use an AnimationController
and an Animation
together in a Flutter app:
// Define an AnimationController final controller = AnimationController( duration: const Duration(seconds: 2), vsync: this, ); // Define an Animation final animation = CurvedAnimation( parent: controller, curve: Curves.easeInOut, ); // Use the AnimationController to drive the animation controller.forward(); // Use the Animation to control the appearance of a widget return FadeTransition( opacity: animation, child: Text('Hello World'), );
In this example, the AnimationController
is used to drive the animation of a FadeTransition
widget, and the CurvedAnimation
is used to define the curve of the animation. The AnimationController
is responsible for controlling the state of the animation, while the Animation
is responsible for representing the value of the animation at a given point in time.