Animation In Flutter: Animation Class, Tween & CurvedAnimation
How to create custom animation? What exactly is Animation class? What is Tween animation? CurvedAnimation: What is it and How to use it?

Search for a command to run...
How to create custom animation? What exactly is Animation class? What is Tween animation? CurvedAnimation: What is it and How to use it?

Woah!! Thanks Nicholas ๐
It was relevant information! To Hire developers is not a cup of tea for every other business person. I thought of trying something new, and I chose a portal named Eiliana.com. I think my experimental idea worked superbly. It is an amazing platform to hire talent per the business needs; the services are also mind-blowing.
Lessons from Code, Content, and Consistency

Reliability basics: Outbox pattern + why it matters

Introducing Kafka/Redpanda + move to event-driven workflow

Connect Orders โ Inventory (first working service-to-service flow)

Inventory service + gRPC + proto contracts

AnimationController to control our animation. We will further customize our basketball animation in this article.
Animation is a core library of the Flutter. This is an abstract class. It means we won't be able to instantiate it.
Animation instance in our app.class _MyHomePageState extends State<MyHomePage> with TickerProviderStateMixin {
late Animation _animation;
//.....
}

double. Because we want to translate the ball position which is of type double. So let's update the Animation type.class _MyHomePageState extends State<MyHomePage> with TickerProviderStateMixin {
late Animation<double> _animation;
//.....
}
abstract class. It has no idea what is going on on-screen. It only understands the values that are passed to it and the state of that specific animation.upperBound and lowerBound values of the animation, i.e. the begin and end values.begin and end points. We use that interpolated value to animate our widget.begin value and one end value.
begin to end value.
Tween<T>. For example: Tween<double>Tween<double>.class _MyHomePageState extends State<MyHomePage> with TickerProviderStateMixin {
late AnimationController _controller;
late Animation<double> _animation;
@override
void initState() {
super.initState();
_controller = AnimationController(
duration: const Duration(milliseconds: 500),
vsync: this,
);
_animation = Tween<double>(begin: 0.0, end: 10.0).animate(_controller); //here
_animation .addListener(() {
setState(() {});
});
_controller.repeat(reverse: true);
}
//....
}
Tween<double>, which is .animate(). This is because the Tween<double> function returns a result of type Animatable rather than Animation. So, to retrieve a value of type Animation, Tween contains a function called animate() that returns an Animation value..animate() requires an instance of an AnimationController as an argument. As a result, we've passed our _controller. _animation.addListener(() {
print(_animation.value);
});

late Animation _colorTween;
@override
void initState() {
super.initState();
//...
_colorTween = ColorTween(begin: Colors.green, end: Colors.blue)
.animate(_controller);
_controller.addListener(() {
print(_animation.value);
});
_controller.forward();
}

As you can see, we now have all of the interpolated values that are in the range of Colors.green to Colors.blue. How cool is that !! ๐คฉ
Let's complete our bouncing ball example by supplying the _animation.value in the Offset
Transform.translate(
offset: Offset(180.0, _animation.value),
child: Image.asset(
"assets/images/basketball.png",
height: 70,
width: 70,
fit: BoxFit.contain,
),
)

Wow, that seems to be working!! However, the problem from the previous article remains, i.e that the ball bouncing is neither smooth nor feels like a genuine ball bouncing.
CurvedAnimation to see how we may address this problem.Curves in animation?CurvedAnimation for our Bouncing Ball example:@override
void initState() {
super.initState();
// ....
final _curvedAnimation = CurvedAnimation(
parent: _controller,
curve: Curves.fastOutSlowIn,
);
// give `_curvedAnimation` instance in the `.animate()` instead `_controller`
_animation =
Tween<double>(begin: 680.0, end: 400.0).animate(_curvedAnimation);
// ...
}


fastOutSlowIn curve. In Flutter, there are far too many different curves to choose from. You can see more curves by following the link below:
