Unverified Commit cd6b2a35 authored by Taha Tesser's avatar Taha Tesser Committed by GitHub

Improve `Hero` examples (#103095)

parent 13d76b29
...@@ -13,13 +13,8 @@ class HeroApp extends StatelessWidget { ...@@ -13,13 +13,8 @@ class HeroApp extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return MaterialApp( return const MaterialApp(
home: Scaffold( home: HeroExample(),
appBar: AppBar(title: const Text('Hero Sample')),
body: const Center(
child: HeroExample(),
),
),
); );
} }
} }
...@@ -29,16 +24,16 @@ class HeroExample extends StatelessWidget { ...@@ -29,16 +24,16 @@ class HeroExample extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Column( return Scaffold(
appBar: AppBar(title: const Text('Hero Sample')),
body: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[ children: <Widget>[
const SizedBox( const SizedBox(height: 20.0),
height: 20.0,
),
ListTile( ListTile(
leading: Hero( leading: const Hero(
tag: 'hero-rectangle', tag: 'hero-rectangle',
child: _box(const Size(50, 50)), child: BoxWidget(size: Size(50.0, 50.0)),
), ),
onTap: () => _gotoDetailsPage(context), onTap: () => _gotoDetailsPage(context),
title: const Text( title: const Text(
...@@ -46,14 +41,7 @@ class HeroExample extends StatelessWidget { ...@@ -46,14 +41,7 @@ class HeroExample extends StatelessWidget {
), ),
), ),
], ],
); ),
}
Widget _box(Size size) {
return Container(
width: size.width,
height: size.height,
color: Colors.blue,
); );
} }
...@@ -63,18 +51,28 @@ class HeroExample extends StatelessWidget { ...@@ -63,18 +51,28 @@ class HeroExample extends StatelessWidget {
appBar: AppBar( appBar: AppBar(
title: const Text('Second Page'), title: const Text('Second Page'),
), ),
body: Center( body: const Center(
child: Column( child: Hero(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Hero(
tag: 'hero-rectangle', tag: 'hero-rectangle',
child: _box(const Size(200, 200)), child: BoxWidget(size: Size(200.0, 200.0)),
),
],
), ),
), ),
), ),
)); ));
} }
} }
class BoxWidget extends StatelessWidget {
const BoxWidget({Key? key, required this.size}) : super(key: key);
final Size size;
@override
Widget build(BuildContext context) {
return Container(
width: size.width,
height: size.height,
color: Colors.blue,
);
}
}
...@@ -18,13 +18,8 @@ class HeroApp extends StatelessWidget { ...@@ -18,13 +18,8 @@ class HeroApp extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return MaterialApp( return const MaterialApp(
home: Scaffold( home: HeroExample(),
appBar: AppBar(title: const Text('Hero Sample')),
body: const Center(
child: HeroExample(),
),
),
); );
} }
} }
...@@ -34,12 +29,17 @@ class HeroExample extends StatelessWidget { ...@@ -34,12 +29,17 @@ class HeroExample extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Column( return Scaffold(
appBar: AppBar(title: const Text('Hero Sample')),
body: Column(
children: <Widget>[ children: <Widget>[
ListTile( ListTile(
leading: Hero( leading: Hero(
tag: 'hero-default-tween', tag: 'hero-default-tween',
child: _box(size: 50.0, color: Colors.red[700]!.withOpacity(0.5)), child: BoxWidget(
size: const Size(50.0, 50.0),
color:Colors.red[700]!.withOpacity(0.5),
),
), ),
title: const Text( title: const Text(
'This red icon will use a default rect tween during the hero flight.', 'This red icon will use a default rect tween during the hero flight.',
...@@ -52,7 +52,10 @@ class HeroExample extends StatelessWidget { ...@@ -52,7 +52,10 @@ class HeroExample extends StatelessWidget {
createRectTween: (Rect? begin, Rect? end) { createRectTween: (Rect? begin, Rect? end) {
return MaterialRectCenterArcTween(begin: begin, end: end); return MaterialRectCenterArcTween(begin: begin, end: end);
}, },
child: _box(size: 50.0, color: Colors.blue[700]!.withOpacity(0.5)), child: BoxWidget(
size: const Size(50.0, 50.0),
color:Colors.blue[700]!.withOpacity(0.5),
),
), ),
title: const Text( title: const Text(
'This blue icon will use a custom rect tween during the hero flight.', 'This blue icon will use a custom rect tween during the hero flight.',
...@@ -64,13 +67,7 @@ class HeroExample extends StatelessWidget { ...@@ -64,13 +67,7 @@ class HeroExample extends StatelessWidget {
child: const Text('Tap to trigger hero flight'), child: const Text('Tap to trigger hero flight'),
), ),
], ],
); ),
}
Widget _box({double? size, Color? color}) {
return Container(
color: color,
child: FlutterLogo(size: size),
); );
} }
...@@ -89,15 +86,15 @@ class HeroExample extends StatelessWidget { ...@@ -89,15 +86,15 @@ class HeroExample extends StatelessWidget {
createRectTween: (Rect? begin, Rect? end) { createRectTween: (Rect? begin, Rect? end) {
return MaterialRectCenterArcTween(begin: begin, end: end); return MaterialRectCenterArcTween(begin: begin, end: end);
}, },
child: _box( child: BoxWidget(
size: 400.0, size: const Size(400.0, 400.0),
color: Colors.blue[700]!.withOpacity(0.5), color: Colors.blue[700]!.withOpacity(0.5),
), ),
), ),
Hero( Hero(
tag: 'hero-default-tween', tag: 'hero-default-tween',
child: _box( child: BoxWidget(
size: 400.0, size: const Size(400.0, 400.0),
color: Colors.red[700]!.withOpacity(0.5), color: Colors.red[700]!.withOpacity(0.5),
), ),
), ),
...@@ -108,3 +105,23 @@ class HeroExample extends StatelessWidget { ...@@ -108,3 +105,23 @@ class HeroExample extends StatelessWidget {
)); ));
} }
} }
class BoxWidget extends StatelessWidget {
const BoxWidget({
Key? key,
required this.size,
required this.color,
}) : super(key: key);
final Size size;
final Color color;
@override
Widget build(BuildContext context) {
return Container(
width: size.width,
height: size.height,
color: color,
);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment