I have an image in one page of the PageView. I want to animate this image to the next page when i go to it, sort of like when you use Hero animations in navigator page transitions. Any ideas how this can be achieved?
The first one is tag which is used as identifier. When moving to another page, Flutter will create the transition animation if each page contains a Hero with the same tag value. You are also required to pass child which is the Widget where the hero animation will be applied on. Creating a Hero is very simple.
The PageView widget allows the user to transition between different screens in their flutter application. All you need to set it up are a PageViewController and a PageView. scrollDirection: It sets the axis of scrolling ( Vertical or horizontal ).
The hero refers to the widget that flies between screens. Create a hero animation using Flutter’s Hero widget. Fly the hero from one screen to another. Animate the transformation of a hero’s shape from circular to rectangular while flying it from one screen to another.
To do so, you need to pass a function as placeholderBuilder. The passed function is responsible to return the placeholder widget. If the placeholderBuilder is only defined on the second page's Hero, the widget returned by HeroPlaceholderBuilder function is only displayed on the second page Hero 's child.
In order to achieve an animation similar to the hero animation. Basically what we will implement is this, you will need 5 elements:
Now in order to create this animation that spans the 2 screens we will need to use the overlay that is present in flutter. link
This is the most flexible between all of the available options since you have access to the widget in all of its states. However you must be very careful when using this method as it might cause a slowdown if not properly implemented.
This packages does what you want https://pub.dev/packages/coast
It is essentially taking the same approach as Flutter’s Hero and HeroController: Detect when a transition is started, search through the element trees of the source and target pages for the widgets marked for animation (heroes, crabs), pair them up based on their tags, and finally create an entry in an Overlay whose position and size is the interpolation between those on the source and target pages.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With