Skip to content

Instantly share code, notes, and snippets.

@kumamotone
Created March 17, 2025 13:03
Show Gist options
  • Save kumamotone/7fe5a57d64a3fa15bee105cd71c4564a to your computer and use it in GitHub Desktop.
Save kumamotone/7fe5a57d64a3fa15bee105cd71c4564a to your computer and use it in GitHub Desktop.
DartPad Gist
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Hero Sample',
theme: ThemeData(primarySwatch: Colors.blue),
home: const Page1(),
);
}
}
class Page1 extends StatelessWidget {
const Page1({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Page1')),
body: Center(
child: GestureDetector(
onTap: () {
// Page2
Navigator.of(
context,
).push(MaterialPageRoute(builder: (context) => const Page2()));
},
child: Hero(
tag: 'heroSample',
child: Container(
width: 100,
height: 100,
color: Colors.blue,
child: const Center(
child: Text('Page1', style: TextStyle(color: Colors.white)),
),
),
),
),
),
);
}
}
class Page2 extends StatelessWidget {
const Page2({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Page2')),
body: Center(
child: GestureDetector(
onTap: () {
// Page3
Navigator.of(
context,
).push(MaterialPageRoute(builder: (context) => const Page3()));
},
child: Hero(
tag: 'heroSample',
child: Container(
width: 200,
height: 200,
color: Colors.blue,
child: const Center(
child: Text(
'Page2',
style: TextStyle(color: Colors.white, fontSize: 24),
),
),
),
),
),
),
);
}
}
class Page3 extends StatelessWidget {
const Page3({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Page3')),
body: Center(
child: Hero(
tag: 'heroSample',
child: Container(
width: 300,
height: 300,
color: Colors.blue,
child: const Center(
child: Text(
'Page3',
style: TextStyle(color: Colors.white, fontSize: 32),
),
),
),
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment