Flutter Development (Day-13):
- In this post we are going to talk about basic animations in Flutter
- First we start the animation by creating two objects Animation animation, AnimationController animationController.
- Animation lets us deal with different types of animations like Tween.
- The tween is something in which you specify the input output range. Here begin is set to -1 and end is 0.0 which means the animation happens from out of the screen to the center of the screen. or rather, from the left most edge to the center of the app. We are also doing an ease in animation, so we specify the curve as fast out slow in.
- In the initState we provide the animation because the animation should occur when user launches the app.
void initState() {
super.initState();
animationController = AnimationController(
vsync: this,
duration: Duration(
seconds: 3,
),
);
animation = Tween<double>(
begin: -1.0,
end: 0.0,
).animate(
CurvedAnimation(
curve: Curves.fastOutSlowIn,
parent: animationController,
),
);
// Delayed animation
delayedAnimation = Tween<double>(
begin: -0.2,
end: 0.0,
).animate(
CurvedAnimation(
parent: animationController,
curve: Interval(
0.6,
1.0,
curve: Curves.fastOutSlowIn,
),
),
);
animationController.repeat();
}
- All the animations are controlled by animationController obj.Here our app is extended with singleTickerProviderStateMixin.It is used to track every frame of the animation like clock ticks for every second.Then we provide the duration of the animation.
- The animation here we are using is Tween.Tween is used to specify range of values means in between those range the animation should occur.
- Delayed Animation is used to specify some delay there we provide Interval which is slightly greater than -1.0 to 0.0.You can observe it in the below video.
- animationController.repeat() or animationController.forward() repeat() stands for it keeps on repeating the animation and forward() appears only once.
Widget build(BuildContext context) {
final double width = MediaQuery.of(context).size.width;
final double height = MediaQuery.of(context).size.height;
return AnimatedBuilder(
animation: animationController,
builder: (BuildContext context, Widget child) {
return Scaffold();
});
- Here We returned AnimatedBuilder as root widget and builder will return a child Widget
Transform(
transform: Matrix4.translationValues(
animation.value * width, 0.0, 0.0),
child: Container(
color: Colors.red,
width: 200.0,
height: 200.0,
child: Center(
child: Text(
"BASIC ANIMATION",
style: TextStyle(color: Colors.white),
),
),
),
),
transform: Matrix4.translationValues(
animation.value * width, 0.0, 0.0),
child: Container(
color: Colors.red,
width: 200.0,
height: 200.0,
child: Center(
child: Text(
"BASIC ANIMATION",
style: TextStyle(color: Colors.white),
),
),
),
),
- Wrap the container with Transform widget which is used to transform or enables us do more interaction for the user.
- If you want any doubts or errors please email me or comment in the Post message.Email is provided in the profile section.
- All source code : Click Here.
- If you are following this tutorial / blog please leave your opinion 👀 / say Hii ✋/ Your e-mail in the comment section that I can improve myself and it will gives boost for me to do more tutorials.
- If you have any doubts feel free to ask me in the comment section or email me ramubugudi4@gmail.com I can definetly give reply.
Comments
Post a Comment