Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to animate old page during transition in flutter?

I made a custom transition for my iOS project, and now I want to move the project to Flutter. The transition is fading out the old page, and fading in the new one.

But I cannot achieve this by overriding the PageRoute.

I did some research on this:

There's a similar question Animate route that is going out / being replaced

From the accepted answer, I know there's a parameter 'secondaryAnimation' which may be useful to achieve it, but after trying to use the code from it, I still cannot animate the old page, all transitions have happened to the new page (the 'child' widget).

Can I get an 'old page' instance from the buildTransition method for animating? Or is there a better way to animate the old page?

Thanks!

like image 338
RockingDice Avatar asked Sep 20 '18 06:09

RockingDice


1 Answers

I think that secondaryAnimation is used when transitioning to another page. So for your initial route, you'd have to specify the animation of it going away using secondaryAnimation and on your second page you use animation to animate how it appears.

It's a bit awkward that you have to use secondaryAnimation when creating the first route, because it means that it will be used for any transition away from that route. So, with PageRouteBuilder, you can't, for example, let the old page slide to the left when transitioning to page B but slide up when transitioning to page C.

like image 191
spkersten Avatar answered Oct 18 '22 07:10

spkersten