Skip to content

Commit 1425164

Browse files
authored
Merge pull request FlutterOpen#35 from FlutterOpen/dev
add the hero Animation that is used in the switching two pages.
2 parents 96d3ce2 + 9ed4e1e commit 1425164

File tree

6 files changed

+94
-0
lines changed

6 files changed

+94
-0
lines changed

lib/const/page_item_const.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,4 +197,9 @@ const PAGE_ITEMS = [
197197
"img": PageImage.FLUTTER_OPEN,
198198
"click": PageName.ANIM_CROSS_FADE,
199199
},
200+
{
201+
"title": PageName.ANIM_HERO,
202+
"img": PageImage.FLUTTER_OPEN,
203+
"click": PageName.ANIM_HERO,
204+
},
200205
];

lib/const/page_name_const.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,5 @@ class PageName {
4444
static const ANIMATION = "AnimationPage";
4545
static const ANIM_CONTAINER = "AnimationContainer";
4646
static const ANIM_CROSS_FADE = "AnimationCrossFade";
47+
static const ANIM_HERO = "HeroPage";
4748
}

lib/main.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class FlutterOpenApp extends StatelessWidget {
5858
PageName.ANIMATION: (context) => AnimationPage(),
5959
PageName.ANIM_CONTAINER: (context) => AnimatedContainerPage(),
6060
PageName.ANIM_CROSS_FADE: (context) => AnimCrossFadePage(),
61+
PageName.ANIM_HERO: (context) => HeroPage(),
6162
},
6263
);
6364
}

lib/page/anim/HeroPage.dart

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
///
2+
/// Created by NieBin on 2019/6/8
3+
/// Github: https://github.com/nb312
4+
5+
///
6+
import "package:flutter/material.dart";
7+
import 'package:flutter_widgets/const/_const.dart';
8+
import 'PhotoHero.dart';
9+
10+
class HeroPage extends StatefulWidget {
11+
@override
12+
_HeroState createState() => _HeroState();
13+
}
14+
15+
class _HeroState extends State<HeroPage> {
16+
@override
17+
Widget build(BuildContext context) {
18+
return Scaffold(
19+
appBar: AppBar(
20+
title: const Text(PageName.ANIM_HERO),
21+
),
22+
body: Center(
23+
child: PhotoHero(
24+
photo: PageImage.FLUTTER_OPEN,
25+
width: 400.0,
26+
onTap: () {
27+
Navigator.of(context)
28+
.push(MaterialPageRoute<void>(builder: (BuildContext context) {
29+
return Scaffold(
30+
appBar: AppBar(
31+
title: const Text('Change pic Page'),
32+
),
33+
body: Container(
34+
// The blue background emphasizes that it's a new route.
35+
color: RED_LIGHT,
36+
padding: const EdgeInsets.all(16.0),
37+
alignment: Alignment.topLeft,
38+
child: PhotoHero(
39+
photo: PageImage.FLUTTER_OPEN,
40+
width: 100.0,
41+
onTap: () {
42+
Navigator.of(context).pop();
43+
},
44+
),
45+
),
46+
);
47+
}));
48+
},
49+
),
50+
),
51+
);
52+
}
53+
}

lib/page/anim/PhotoHero.dart

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
///
2+
/// Created by NieBin on 2019/6/8
3+
/// Github: https://github.com/nb312
4+
5+
import "package:flutter/material.dart";
6+
7+
class PhotoHero extends StatelessWidget {
8+
const PhotoHero({Key key, this.photo, this.onTap, this.width})
9+
: super(key: key);
10+
11+
final String photo;
12+
final VoidCallback onTap;
13+
final double width;
14+
15+
Widget build(BuildContext context) {
16+
return SizedBox(
17+
width: width,
18+
child: Hero(
19+
tag: photo,
20+
child: Material(
21+
color: Colors.transparent,
22+
child: InkWell(
23+
onTap: onTap,
24+
child: Image.asset(
25+
photo,
26+
fit: BoxFit.contain,
27+
),
28+
),
29+
),
30+
),
31+
);
32+
}
33+
}

lib/page/anim/_anim.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
export "AnimationPage.dart";
66
export 'AnimatedContainerPage.dart';
77
export 'AnimCrossFadePage.dart';
8+
export 'HeroPage.dart';

0 commit comments

Comments
 (0)