text stringlengths 1 474 |
|---|
row of three circular images appears at the bottom of the route. |
Tapping any of the circular images flies that image to a new route |
that displays it with a square shape. |
Tapping the square image flies the hero back to |
the original route, displayed with a circular shape.Before moving to the sections specific to |
standard |
or radial hero animations, |
read basic structure of a hero animation |
to learn how to structure hero animation code, |
and behind the scenes to understand |
how Flutter performs a hero animation.<topic_end> |
<topic_start> |
Basic structure of a hero animation |
<topic_end> |
<topic_start>What's the point? |
Terminology: |
If the concept of tweens or tweening is new to you, |
see the Animations in Flutter tutorial.Hero animations are implemented using two Hero |
widgets: one describing the widget in the source route, |
and another describing the widget in the destination route. |
From the user’s point of view, the hero appears to be shared, and |
only the programmer needs to understand this implementation detail. |
Hero animation code has the following structure:Flutter calculates the tween that animates the Hero’s bounds from |
the starting point to the endpoint (interpolating size and position), |
and performs the animation in an overlay.The next section describes Flutter’s process in greater detail.<topic_end> |
<topic_start> |
Behind the scenes |
The following describes how Flutter performs the |
transition from one route to another.Before transition, the source hero waits in the source |
route’s widget tree. The destination route does not yet exist, |
and the overlay is empty.Pushing a route to the Navigator triggers the animation. |
At t=0.0, Flutter does the following:Calculates the destination hero’s path, offscreen, |
using the curved motion as described in the Material |
motion spec. Flutter now knows where the hero ends up.Places the destination hero in the overlay, |
at the same location and size as the source hero. |
Adding a hero to the overlay changes its Z-order so that it |
appears on top of all routes.Moves the source hero offscreen.As the hero flies, its rectangular bounds are animated using |
Tween<Rect>, specified in Hero’s |
createRectTween property. |
By default, Flutter uses an instance of |
MaterialRectArcTween, which animates the |
rectangle’s opposing corners along a curved path. |
(See Radial hero animations for an example |
that uses a different Tween animation.)When the flight completes:Flutter moves the hero widget from the overlay to |
the destination route. The overlay is now empty.The destination hero appears in its final position |
in the destination route.The source hero is restored to its route.Popping the route performs the same process, |
animating the hero back to its size |
and location in the source route.<topic_end> |
<topic_start> |
Essential classes |
The examples in this guide use the following classes to |
implement hero animations:<topic_end> |
<topic_start> |
Standard hero animations |
<topic_end> |
<topic_start>What's the point? |
Standard hero animation codeEach of the following examples demonstrates flying an image from one |
route to another. This guide describes the first example.<topic_end> |
<topic_start> |
What’s going on? |
Flying an image from one route to another is easy to implement |
using Flutter’s hero widget. When using MaterialPageRoute |
to specify the new route, the image flies along a curved path, |
as described by the Material Design motion spec.Create a new Flutter example and |
update it using the files from the hero_animation.To run the example:<topic_end> |
<topic_start> |
PhotoHero class |
The custom PhotoHero class maintains the hero, |
and its size, image, and behavior when tapped. |
The PhotoHero builds the following widget tree:Here’s the code:Key information:<topic_end> |
<topic_start> |
HeroAnimation class |
The HeroAnimation class creates the source and destination |
PhotoHeroes, and sets up the transition.Here’s the code:Key information:<topic_end> |
<topic_start> |
Radial hero animations |
<topic_end> |
<topic_start>What's the point? |
Flying a hero from one route to another as it transforms |
from a circular shape to a rectangular shape is a slick |
effect that you can implement using Hero widgets. |
To accomplish this, the code animates the intersection of |
two clip shapes: a circle and a square. |
Throughout the animation, the circle clip (and the image) |
scales from minRadius to maxRadius, while the square |
clip maintains constant size. At the same time, |
the image flies from its position in the source route to its |
position in the destination route. For visual examples |
of this transition, see Radial transformation |
in the Material motion spec.This animation might seem complex (and it is), but you can customize the |
provided example to your needs. The heavy lifting is done for you.Radial hero animation codeEach of the following examples demonstrates a radial hero animation. |
This guide describes the first example.Pro tip: |
The radial hero animation involves intersecting a round shape with |
a square shape. This can be hard to see, even when slowing |
the animation with timeDilation, so you might consider enabling |
the debugPaintSizeEnabled flag during development.<topic_end> |
<topic_start> |
What’s going on? |
The following diagram shows the clipped image at the beginning |
(t = 0.0), and the end (t = 1.0) of the animation.The blue gradient (representing the image), indicates where the clip |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.