Flutter – Parenting Animations

Hi Friends,

Hope you are all well. In this post let’s talk about parenting animations. Or resizing the widget in a fancy way onscreen.. :)

To learn the basics of flutter get my course – Click here.

Other flutter courses – here. (Affliate link)

This is a sequel to my previous posts on animations. If you haven’t read them yet I would kindly advise you to do so by following the below links.

Basics of Animation – Click here.

Delayed Animations – Click here.

Let’s begin.

A video screencast of this post.

 

First of all what’s a parenting animation ? And how does it look like ?

Wow, looks nice right ? So why is this called a parenting animation ? Well, if you notice this carefully, you’ll see that there are two animations happening at the same time. One is the box moving along the x axis, and the other is a resize happening in the height and width of one of the boxes.

Since the top box does two animations it’s a child right ? The movement along the x-axis is done by both the boxes, it’s the parent and the resize happens only in one of them, it’s child. So this is called a parenting animation.

Alright, now how are we going to bring this into our application ? Let’s get started on that.

Create a new app and open up main.dart file and add the below code.

Whoa, that’s too much code.. Alright, Let’s break this down.

This snippet is the one where we define the animations right ? It just shows a couple of easeIn animations, but watch the Tweens. The parent animation tween defines the start and end values as -0.25 and 0.0. This is to move the element or in our case the login form along the x-axis from somewhere on the left to the centre.

The childAnimation tween defines the start and end values as 20.0 and 125.0. This defines the height and width of the form that’s about to be resized over a period of time. Let’s see how this goes later on.

Now regarding the actual animation. Look at this snippet

This is the snippet that handles the form. Notice that we are using two different AnimatedBuilders, one for the movement and another for the resizing.

For moving it we are using Matrix4.translateValues() whereas for resizing we are simply placing a container and mapping its height and width values to the values from the childAnimation as it happens.

That’s it. As simple as that. Now try to run this code (preferrably on an app) and watch the effect as it happens before your eyes.

Webp.net-gifmaker (7)

Nice right ?

Hope this helped you guys. If you found this helpful, kindly share it with someone and help them too.

Donate to keep this site alive – here.

(If you want to donate but can’t, it’s fine just subscribe to my youtube channel).

Join our flutter community – here.

Thanks for reading. Peace.. :)

Liked it? Take a second to support admin on Patreon!