Intermediate
Page Transitions with Hero Animations in Flutter
· 7 min read

What Is the Hero Widget?
Hero lets a widget that shares the same tag value on two different pages animate automatically from its position on one page to its position on the other during a page transition. Watching a small thumbnail grow and 'fly' into its spot on the detail page when the user taps a list item noticeably raises the perceived quality of an app.

Basic Usage: List → Detail
You give the Hero widgets on both pages the same tag, and Flutter takes care of the rest. tag is usually derived from the item's unique identifier, so there's no collision when a list has more than one item.
// List page
ListTile(
leading: Hero(
tag: 'urun-${urun.id}',
child: Image.asset(urun.gorsel, width: 56, height: 56),
),
title: Text(urun.ad),
onTap: () => Navigator.push(
context,
MaterialPageRoute(builder: (_) => UrunDetayPage(urun: urun)),
),
)
// Detail page
Hero(
tag: 'urun-${urun.id}',
child: Image.asset(urun.gorsel, width: double.infinity, height: 300),
)How It Works
When Navigator.push opens a new page through a PageRoute, Flutter finds the Heroes sharing the same tag on the current and incoming pages, reads both of their positions and sizes (their RenderBox), and builds a 'flight' animation between them. That animation plays in a separate overlay on top of both pages for the duration of the transition; once it finishes, the widget settles into its normal spot on the destination page.
Customizing with flightShuttleBuilder
By default, the widget shown during the flight is the destination Hero's child. flightShuttleBuilder lets you override that and show something different during the transition — a version with a subtle scale animation, for example.
Hero(
tag: 'urun-${urun.id}',
flightShuttleBuilder: (context, animation, direction, fromContext, toContext) {
return Material(
color: Colors.transparent,
child: ScaleTransition(
scale: animation.drive(Tween(begin: 0.95, end: 1.0)),
child: toContext.widget,
),
);
},
child: Image.asset(urun.gorsel),
)Customizing the Flight Path with createRectTween
By default, Hero moves along a straight line between the start and end rectangles. createRectTween lets you customize that path — Material Design's own MaterialRectArcTween, for instance, bows the transition along a slight curve, which reads as more natural.
Hero(
tag: 'urun-${urun.id}',
createRectTween: (begin, end) {
return MaterialRectArcTween(begin: begin, end: end);
},
child: Image.asset(urun.gorsel),
)Things to Watch Out For
1. No Two Heroes with the Same Tag on One Page
If a single route (page) contains two Heroes with the same tag, Flutter throws: 'There are multiple heroes that share the same tag.' In list screens, always derive the tag from the item's unique ID, never from its index — an item can change even if its index stays the same after a reorder.
2. A PageRoute Is Required
Hero animations only work for transitions opened with Navigator.push through a PageRoute (MaterialPageRoute, CupertinoPageRoute, etc.). Helpers like showDialog or showModalBottomSheet may use a different route type, in which case the Hero animation simply won't fire.
Conclusion
Hero is an animation where most of the work is just giving two widgets the same tag, yet it raises the perceived polish of a transition dramatically. Customize what's shown mid-flight with flightShuttleBuilder, shape the motion path with createRectTween, and just make sure your tags are unique and the transition goes through a PageRoute.