Skip to content

Commit cc48f47

Browse files
committed
add the navigator widget.
1 parent 4ec7a71 commit cc48f47

File tree

6 files changed

+218
-0
lines changed

6 files changed

+218
-0
lines changed

lib/const/page_item_const.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,11 @@ const PAGE_ITEMS = [
272272
"img": PageImage.FLUTTER_OPEN,
273273
"click": PageName.INTER_POINTER,
274274
},
275+
{
276+
"title": PageName.INTER_NAV,
277+
"img": PageImage.FLUTTER_OPEN,
278+
"click": PageName.INTER_NAV,
279+
},
275280
{
276281
"title": PageName.ASYNC_FUTURE,
277282
"img": PageImage.FLUTTER_OPEN,

lib/const/page_name_const.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class PageName {
6060
static const INTER_DISMISSIBLE = "Dismissible";
6161
static const INTER_POINTER = "AbsorbPointer";
6262
static const INTER_SCROLLABLE = "Scrollable";
63+
static const INTER_NAV = "Navigator";
6364
static const ASYNC_FUTURE = "FutureBuilder";
6465
static const ASYNC_STREAM_BUILDER = "StreamBuilder";
6566
}

lib/main.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ class FlutterOpenApp extends StatelessWidget {
7373
PageName.INTER_GESTURE: (context) => GesturePage(),
7474
PageName.INTER_DISMISSIBLE: (context) => DismissiblePage(),
7575
PageName.INTER_POINTER: (context) => PointerPage(),
76+
PageName.INTER_NAV: (context) => NavigatorPage(),
7677
PageName.ASYNC_FUTURE: (context) => FuturePage(),
7778
PageName.ASYNC_STREAM_BUILDER: (context) => StreamBuilderPage(),
7879
},

lib/page/interation/NavPage.dart

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
///
2+
/// Created by NieBin on 2019/6/15
3+
/// Github: https://github.com/nb312
4+
/// Email: niebin312@gmail.com
5+
6+
import "package:flutter/material.dart";
7+
import 'package:flutter_widgets/const/_const.dart';
8+
9+
class NavPage extends StatefulWidget {
10+
@override
11+
_NavState createState() => _NavState();
12+
}
13+
14+
class _NavState extends State<NavPage> {
15+
@override
16+
Widget build(BuildContext context) {
17+
return Scaffold(
18+
appBar: AppBar(
19+
title: Text("NavPage"),
20+
),
21+
body: Center(
22+
child: FloatingActionButton(
23+
onPressed: () {
24+
Navigator.pop(context, "My name is Nie Bin");
25+
},
26+
child: Text("back"),
27+
backgroundColor: BLUE_LIGHT,
28+
),
29+
));
30+
}
31+
}
Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
///
2+
/// Created by NieBin on 2019/6/15
3+
/// Github: https://github.com/nb312
4+
/// Email: niebin312@gmail.com
5+
6+
import "package:flutter/material.dart";
7+
import 'package:flutter_widgets/const/_const.dart';
8+
import 'NavPage.dart';
9+
10+
class NavigatorPage extends StatefulWidget {
11+
Key _key = GlobalKey<_NavigatorState>();
12+
13+
@override
14+
_NavigatorState createState() => _NavigatorState();
15+
}
16+
17+
class _NavigatorState extends State<NavigatorPage> {
18+
Future<void> _startPage() async {
19+
var content = await Navigator.push(
20+
context,
21+
MaterialPageRoute<String>(
22+
builder: (context) => NavPage(),
23+
),
24+
);
25+
print("Content: $content");
26+
}
27+
28+
Widget _pushWithBack() => FlatButton(
29+
onPressed: () {
30+
print("Hello world");
31+
_startPage();
32+
},
33+
child: Text("jump"),
34+
color: PURPLE,
35+
);
36+
37+
Future<void> _transPage() {
38+
Navigator.push(
39+
context,
40+
PageRouteBuilder(
41+
opaque: false,
42+
barrierColor: GREEN,
43+
pageBuilder: (BuildContext context, _, __) {
44+
return NavPage();
45+
},
46+
transitionsBuilder:
47+
(___, Animation<double> animation, ____, Widget child) {
48+
return FadeTransition(
49+
opacity: animation,
50+
child: RotationTransition(
51+
turns: Tween<double>(begin: 0.5, end: 2.0).animate(animation),
52+
child: child,
53+
),
54+
);
55+
}));
56+
}
57+
58+
Widget _transButton() => FlatButton(
59+
child: Text("Trans"),
60+
color: RED_LIGHT,
61+
onPressed: () {
62+
_transPage();
63+
},
64+
);
65+
66+
Widget _slidButton(BuildContext context) => FlatButton(
67+
child: Text("Slid"),
68+
color: RED_LIGHT,
69+
onPressed: () {
70+
Navigator.push(context, SlideRightRoute(page: NavPage()));
71+
},
72+
);
73+
74+
Widget _doublePage(BuildContext context) => Container(
75+
constraints: BoxConstraints.expand(height: 100),
76+
child: FlatButton(
77+
child: Text("Double Page"),
78+
color: RED_LIGHT,
79+
onPressed: () {
80+
Navigator.push(context,
81+
EnterExitRoute(exitPage: widget, enterPage: NavPage()));
82+
},
83+
),
84+
);
85+
86+
@override
87+
Widget build(BuildContext context) {
88+
return Scaffold(
89+
appBar: AppBar(
90+
title: Text(PageName.INTER_NAV),
91+
),
92+
body: Column(
93+
mainAxisAlignment: MainAxisAlignment.spaceAround,
94+
children: <Widget>[
95+
Container(
96+
constraints: BoxConstraints.expand(height: 100),
97+
child: _pushWithBack(),
98+
),
99+
Container(
100+
constraints: BoxConstraints.expand(height: 100),
101+
child: _transButton(),
102+
),
103+
Container(
104+
constraints: BoxConstraints.expand(height: 100),
105+
child: _slidButton(context),
106+
),
107+
_doublePage(context),
108+
],
109+
),
110+
);
111+
}
112+
}
113+
114+
class SlideRightRoute extends PageRouteBuilder {
115+
final Widget page;
116+
117+
SlideRightRoute({this.page})
118+
: super(
119+
pageBuilder: (
120+
BuildContext context,
121+
Animation<double> animation,
122+
Animation<double> secondaryAnimation,
123+
) =>
124+
page,
125+
transitionsBuilder: (
126+
BuildContext context,
127+
Animation<double> animation,
128+
Animation<double> secondaryAnimation,
129+
Widget child,
130+
) =>
131+
SlideTransition(
132+
position: Tween<Offset>(
133+
begin: const Offset(-1, 0),
134+
end: Offset.zero,
135+
).animate(animation),
136+
child: child,
137+
),
138+
barrierColor: GREEN,
139+
);
140+
}
141+
142+
class EnterExitRoute extends PageRouteBuilder {
143+
final Widget enterPage;
144+
final Widget exitPage;
145+
146+
EnterExitRoute({this.exitPage, this.enterPage})
147+
: super(
148+
pageBuilder: (
149+
BuildContext context,
150+
Animation<double> animation,
151+
Animation<double> secondaryAnimation,
152+
) =>
153+
enterPage,
154+
transitionsBuilder: (
155+
BuildContext context,
156+
Animation<double> animation,
157+
Animation<double> secondaryAnimation,
158+
Widget child,
159+
) =>
160+
Stack(
161+
children: <Widget>[
162+
SlideTransition(
163+
position: new Tween<Offset>(
164+
begin: const Offset(0.0, 0.0),
165+
end: const Offset(-1.0, -1.0),
166+
).animate(animation),
167+
child: exitPage,
168+
),
169+
SlideTransition(
170+
position: new Tween<Offset>(
171+
begin: const Offset(1.0, 1.0),
172+
end: Offset.zero,
173+
).animate(animation),
174+
child: enterPage,
175+
)
176+
],
177+
),
178+
);
179+
}

lib/page/interation/_interaction.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ export "GesturePage.dart";
88
export "DismissiblePage.dart";
99
export "PointerPage.dart";
1010
export "ScrollablePage.dart";
11+
export "NavigatorPage.dart";

0 commit comments

Comments
 (0)