@@ -18,13 +18,8 @@ class HeroApp extends StatelessWidget {
18
18
19
19
@override
20
20
Widget build (BuildContext context) {
21
- return MaterialApp (
22
- home: Scaffold (
23
- appBar: AppBar (title: const Text ('Hero Sample' )),
24
- body: const Center (
25
- child: HeroExample (),
26
- ),
27
- ),
21
+ return const MaterialApp (
22
+ home: HeroExample (),
28
23
);
29
24
}
30
25
}
@@ -34,43 +29,45 @@ class HeroExample extends StatelessWidget {
34
29
35
30
@override
36
31
Widget build (BuildContext context) {
37
- return Column (
38
- children: < Widget > [
39
- ListTile (
40
- leading: Hero (
41
- tag: 'hero-default-tween' ,
42
- child: _box (size: 50.0 , color: Colors .red[700 ]! .withOpacity (0.5 )),
43
- ),
44
- title: const Text (
45
- 'This red icon will use a default rect tween during the hero flight.' ,
32
+ return Scaffold (
33
+ appBar: AppBar (title: const Text ('Hero Sample' )),
34
+ body: Column (
35
+ children: < Widget > [
36
+ ListTile (
37
+ leading: Hero (
38
+ tag: 'hero-default-tween' ,
39
+ child: BoxWidget (
40
+ size: const Size (50.0 , 50.0 ),
41
+ color: Colors .red[700 ]! .withOpacity (0.5 ),
42
+ ),
43
+ ),
44
+ title: const Text (
45
+ 'This red icon will use a default rect tween during the hero flight.' ,
46
+ ),
46
47
),
47
- ),
48
- const SizedBox (height: 10.0 ),
49
- ListTile (
50
- leading: Hero (
51
- tag: 'hero-custom-tween' ,
52
- createRectTween: (Rect ? begin, Rect ? end) {
53
- return MaterialRectCenterArcTween (begin: begin, end: end);
54
- },
55
- child: _box (size: 50.0 , color: Colors .blue[700 ]! .withOpacity (0.5 )),
48
+ const SizedBox (height: 10.0 ),
49
+ ListTile (
50
+ leading: Hero (
51
+ tag: 'hero-custom-tween' ,
52
+ createRectTween: (Rect ? begin, Rect ? end) {
53
+ return MaterialRectCenterArcTween (begin: begin, end: end);
54
+ },
55
+ child: BoxWidget (
56
+ size: const Size (50.0 , 50.0 ),
57
+ color: Colors .blue[700 ]! .withOpacity (0.5 ),
58
+ ),
59
+ ),
60
+ title: const Text (
61
+ 'This blue icon will use a custom rect tween during the hero flight.' ,
62
+ ),
56
63
),
57
- title: const Text (
58
- 'This blue icon will use a custom rect tween during the hero flight.' ,
64
+ const SizedBox (height: 10 ),
65
+ ElevatedButton (
66
+ onPressed: () => _gotoDetailsPage (context),
67
+ child: const Text ('Tap to trigger hero flight' ),
59
68
),
60
- ),
61
- const SizedBox (height: 10 ),
62
- ElevatedButton (
63
- onPressed: () => _gotoDetailsPage (context),
64
- child: const Text ('Tap to trigger hero flight' ),
65
- ),
66
- ],
67
- );
68
- }
69
-
70
- Widget _box ({double ? size, Color ? color}) {
71
- return Container (
72
- color: color,
73
- child: FlutterLogo (size: size),
69
+ ],
70
+ ),
74
71
);
75
72
}
76
73
@@ -89,15 +86,15 @@ class HeroExample extends StatelessWidget {
89
86
createRectTween: (Rect ? begin, Rect ? end) {
90
87
return MaterialRectCenterArcTween (begin: begin, end: end);
91
88
},
92
- child: _box (
93
- size: 400.0 ,
89
+ child: BoxWidget (
90
+ size: const Size ( 400.0 , 400.0 ) ,
94
91
color: Colors .blue[700 ]! .withOpacity (0.5 ),
95
92
),
96
93
),
97
94
Hero (
98
95
tag: 'hero-default-tween' ,
99
- child: _box (
100
- size: 400.0 ,
96
+ child: BoxWidget (
97
+ size: const Size ( 400.0 , 400.0 ) ,
101
98
color: Colors .red[700 ]! .withOpacity (0.5 ),
102
99
),
103
100
),
@@ -108,3 +105,23 @@ class HeroExample extends StatelessWidget {
108
105
));
109
106
}
110
107
}
108
+
109
+ class BoxWidget extends StatelessWidget {
110
+ const BoxWidget ({
111
+ Key ? key,
112
+ required this .size,
113
+ required this .color,
114
+ }) : super (key: key);
115
+
116
+ final Size size;
117
+ final Color color;
118
+
119
+ @override
120
+ Widget build (BuildContext context) {
121
+ return Container (
122
+ width: size.width,
123
+ height: size.height,
124
+ color: color,
125
+ );
126
+ }
127
+ }
0 commit comments