text
stringlengths
1
372
<topic_end>
<topic_start>
what you'll learn
you’ve probably seen hero animations many times. for example, a screen displays
a list of thumbnails representing items for sale. selecting an item flies it to
a new screen, containing more details and a “buy” button. flying an image from
one screen to another is called a hero animation in flutter, though the same
motion is sometimes referred to as a shared element transition.
you might want to watch this one-minute video introducing the hero widget:
this guide demonstrates how to build standard hero animations, and hero
animations that transform the image from a circular shape to a square shape
during flight.
examples: this guide provides examples of each hero animation style at
the following links.
new to flutter?
this page assumes you know how to create a layout
using flutter’s widgets. for more information, see
building layouts in flutter.
terminology:
a route describes a page or screen in a flutter app.
you can create this animation in flutter with hero widgets.
as the hero animates from the source to the destination route,
the destination route (minus the hero) fades into view.
typically, heroes are small parts of the UI, like images,
that both routes have in common. from the user’s perspective
the hero “flies” between the routes. this guide shows how
to create the following hero animations:
standard hero animations
a standard hero animation flies the hero from one route to a new route,
usually landing at a different location and with a different size.
the following video (recorded at slow speed) shows a typical example.
tapping the flippers in the center of the route flies them to the
upper left corner of a new, blue route, at a smaller size.
tapping the flippers in the blue route (or using the device’s
back-to-previous-route gesture) flies the flippers back to
the original route.
radial hero animations
in radial hero animation, as the hero flies between routes
its shape appears to change from circular to rectangular.
the following video (recorded at slow speed),
shows an example of a radial hero animation. at the start, a
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