Fade and Slide transition in Flutter

ref – https://www.youtube.com/watch?v=xIX9Bo_yjvo
https://medium.com/codechai/flutter-animation-basics-explained-with-stacked-cards-9d34108403b8

First we have to refactor our class into a StatefulWidget.

1) extends StatefulWidget
2) @override createState()
3) extends State
4) with SingleTickerProviderStateMixin

When you add your SingleTickerProviderStateMixin, it tells Flutter that there is some animation in this widget and this widget needs to notified about the animation frames of flutter.

Animation controller is one of the basic things necessary for creating magic in flutter. You can imagine this as the dictator of the animation on screen. It contains the duration of the animation and so it will split out values between 0 to 1 based on the duration and the ticker value.
Controller value is 0 -> Start of your animation
Controller value is 1 -> End of your animation

vsync property is related to the Ticker and if the stateful widget has the Mixin, you can pass this to this property.
Animation with just the controller is possible when your animated value is also from just 0 to 1. You can pass the controller value to the widget and start the animation by calling controller.forward()

Tween

Short for in-betweening, the process of generating intermediate frames between two images to give the appearance that the first image evolves smoothly into the second image.

Creating the in-between values is the responsibility of Tween. Tween takes a begin ,end, properties and to create a Animation variable we should use the animate method and pass the controller.

When you call animation.forward() it will produce a smooth animation from the begin Offset value to end Offset value.

Fading in a Text

Wrap some padding around it using a Container

Now let’s start a fade transition. We pass in our animation Controller for the opacity. Our animation controller has an animation time of 1500 milliseconds. Thus, it will animate the opacity from -1 to 0 in 1500 milliseconds.

Run the project and you’ll the text have this fade effect.

Transition the Text

Let’s remove the fade transition from our Text Container. Our Text container should simply be:

We wrap a SlideTransition like so:

child class

So in order to make this work, we have a child class and that houses Text and an Image.

As you can see, it references an injected animation controller. The animation controller in the parent class holds state:

SlideTransition – for position property we assign it a Tween. The tween takes the animationController in order to animate.

FadeTransition – for opacity, we stick in the animation controller, which says duration should be 1.5 seconds.
However, we decide to forgo this feature and just use transition.

In the parent class, we use it like so:

Now when the animation starts, the text will transition from the left and come in towards the right.

Moving the button up

So now using the same tactic, we create another class called Bottom, that will reference the parent class animationController. It will have some static UI widgets which we will animate.

For its build function, we return a slide Transition.

The position needs a Tween. We want it to come from bottom off screen

So we know that it will slide something from offscreen (x is 0, y is 1) up to original position.
That something is a container that holds text: