Hero List
Loading preview
Starting the Flutter app
A beautiful list view with hero animations for smooth transitions between list items and detail views. Perfect for showcasing content with engaging animations.
import 'package:flutter/material.dart';
class Item {
final String title;
final IconData icon;
final Color color;
Item({required this.title, required this.icon, required this.color});
}
final items = [
Item(title: "Home Page", icon: Icons.home, color: Colors.redAccent),
Item(title: "Profile Page", icon: Icons.person, color: Colors.blueAccent),
Item(title: "Settings Page", icon: Icons.settings, color: Colors.cyan),
Item(title: "Email Page", icon: Icons.email, color: Colors.green),
Item(title: "Phone Page", icon: Icons.phone, color: Colors.purpleAccent),
];
class HeroListView extends StatefulWidget {
const HeroListView({super.key});
@override
State<HeroListView> createState() => _HeroListViewState();
}
class _HeroListViewState extends State<HeroListView> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text("Hero List View")),
body: ListView.builder(
itemCount: items.length,
itemBuilder: (context, index) => ListTile(
minTileHeight: 100,
title: Text(items[index].title),
leading: Hero(
tag: "hero_list_item_$index",
child: Container(
width: 60,
height: 100,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: items[index].color.withValues(alpha: 0.1),
),
child: Icon(items[index].icon, color: items[index].color),
),
),
onTap: () => Navigator.push(
context,
MaterialPageRoute(
builder: (context) => HeroListItemPage(index: index),
),
),
),
),
);
}
}
class HeroListItemPage extends StatelessWidget {
final int index;
const HeroListItemPage({super.key, required this.index});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text("Hero List Item Page")),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
children: [
Hero(
tag: "hero_list_item_$index",
child: Container(
width: double.infinity,
height: 250,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: items[index].color.withValues(alpha: 0.1),
),
child: Center(
child: Icon(
items[index].icon,
color: items[index].color,
size: 100,
),
),
),
),
const SizedBox(height: 16),
Text(
items[index].title,
style: Theme.of(context).textTheme.headlineMedium,
),
],
),
),
);
}
}
Add it to your project
Copies the Dart source into your app, so you own it. Flutter SDK only, no extra packages.
First time? Run dart pub global activate fluttertemplates_dev, or read the CLI guide.
How it works
Both screens wrap a Container in a Hero with the same tag, hero_list_item_$index, and pushing a MaterialPageRoute triggers the flight from the 60 px wide thumbnail to the 250 px tall banner. HeroListItemPage receives only an index and reads the top-level items list, so the two screens are tied to that global. _HeroListViewState holds no state.
Adapting it
- Pass an
ItemtoHeroListItemPageinstead ofindex, which removes the dependency onitems. - Build the
Herotag from a stable id once data is dynamic, because index-based tags break if the list reorders between push and pop. - Extend
Itembeyondtitle,iconandcolor, then lay the new fields out under the banner.