Skip to content

Commit 5e37de2

Browse files
author
junwang
committed
new
1 parent 0ce75a9 commit 5e37de2

File tree

4 files changed

+97
-34
lines changed

4 files changed

+97
-34
lines changed

dialog_back_button/lib/page/navigator2/one_page.dart

+34-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import 'package:dialog_back_button/component/common_title_widget.dart';
2-
import 'package:dialog_back_button/page/navigator2/two_page.dart';
2+
import 'package:dialog_back_button/page/navigator2/three_page.dart';
33
import 'package:dialog_back_button/provider/app_state_manager_provider.dart';
44
import 'package:dialog_back_button/route/app_router_util.dart';
55
import 'package:dialog_back_button/route/index.dart';
66
import 'package:dialog_back_button/util/page_util.dart';
77
import 'package:flutter/material.dart';
8-
98
class OnePage extends StatefulWidget {
109
@override
1110
State<StatefulWidget> createState() {
@@ -25,12 +24,39 @@ class _OnePageState extends State<OnePage> {
2524

2625
Widget _buildBody() {
2726
return Center(
28-
child: InkWell(
29-
child: Text("goto two page"),
30-
onTap: () {
31-
AppRouterUtil.getAppState(context).currentAction =
32-
PageAction(state: PageState.addPage, page: TwoPageConfig);
33-
},
27+
child: Column(
28+
mainAxisSize: MainAxisSize.min,
29+
children: [
30+
InkWell(
31+
child: Text(
32+
"goto two page",
33+
style: TextStyle(
34+
fontSize: 16,
35+
),
36+
),
37+
onTap: () {
38+
AppRouterUtil.getAppState(context).currentAction =
39+
PageAction(state: PageState.addPage, page: TwoPageConfig);
40+
},
41+
),
42+
SizedBox(
43+
height: 20,
44+
),
45+
InkWell(
46+
child: Text(
47+
"WillPopScope 失效",
48+
style: TextStyle(
49+
fontSize: 16,
50+
),
51+
),
52+
onTap: () {
53+
AppRouterUtil.getAppState(context).currentAction = PageAction(
54+
state: PageState.addWidget,
55+
widget: ThreePage(),
56+
page: PageConfiguration(key: threePath, path: threePath));
57+
},
58+
),
59+
],
3460
),
3561
);
3662
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import 'package:dialog_back_button/component/common_title_widget.dart';
2+
import 'package:dialog_back_button/route/app_router_util.dart';
3+
import 'package:dialog_back_button/util/page_util.dart';
4+
import 'package:flutter/material.dart';
5+
6+
class ThreePage extends StatefulWidget {
7+
@override
8+
State<StatefulWidget> createState() {
9+
return _ThreePageState();
10+
}
11+
}
12+
13+
class _ThreePageState extends State<ThreePage> {
14+
@override
15+
Widget build(BuildContext context) {
16+
return PageUtil.buildPage(
17+
_buildBody(),
18+
CommonTitleWidget(
19+
title: "Navigator 2.0 four Page",
20+
leftClick: () {
21+
AppRouterUtil.popPage(context);
22+
},
23+
));
24+
}
25+
26+
Widget _buildBody() {
27+
return WillPopScope(
28+
child: Center(
29+
child: Text("WillPopScope 失效"),
30+
),
31+
onWillPop: () {
32+
return _showDialog();
33+
});
34+
}
35+
36+
Future<bool> _showDialog() async {
37+
var result = await showDialog<bool>(
38+
context: context,
39+
builder: (context) => new AlertDialog(
40+
title: new Text('Are you sure?'),
41+
content: new Text('some tip'),
42+
actions: <Widget>[
43+
new GestureDetector(
44+
onTap: () => Navigator.of(context).pop(false),
45+
child: Text("NO"),
46+
),
47+
SizedBox(height: 16),
48+
new GestureDetector(
49+
onTap: () => Navigator.of(context).pop(true),
50+
child: Text("YES"),
51+
),
52+
],
53+
),
54+
);
55+
if (result == true) {
56+
return Future.value(true);
57+
} else {
58+
return Future.value(false);
59+
}
60+
}
61+
}

dialog_back_button/lib/page/navigator2/two_page.dart

-26
Original file line numberDiff line numberDiff line change
@@ -32,32 +32,6 @@ class _TwoPageState extends State<TwoPage> {
3232
);
3333
}
3434

35-
Future<bool> _showDialog() async {
36-
var result = await showDialog<bool>(
37-
context: context,
38-
builder: (context) => new AlertDialog(
39-
title: new Text('Are you sure?'),
40-
content: new Text('some tip'),
41-
actions: <Widget>[
42-
new GestureDetector(
43-
onTap: () => Navigator.of(context).pop(false),
44-
child: Text("NO"),
45-
),
46-
SizedBox(height: 16),
47-
new GestureDetector(
48-
onTap: () => Navigator.of(context).pop(true),
49-
child: Text("YES"),
50-
),
51-
],
52-
),
53-
);
54-
if (result == true) {
55-
return Future.value(true);
56-
} else {
57-
return Future.value(false);
58-
}
59-
}
60-
6135
Future<bool> _onBackPressed() async {
6236
var result = await showDialog<bool>(
6337
context: context,

dialog_back_button/lib/route/ui_pages.dart

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import 'index.dart';
44

55
const String onePath = '/one';
66
const String twoPath = '/two';
7+
const String threePath = '/three';
8+
const String fourPath = "/four";
79

810
class PageConfiguration {
911
final String key;

0 commit comments

Comments
 (0)