File tree 4 files changed +97
-34
lines changed
4 files changed +97
-34
lines changed Original file line number Diff line number Diff line change 1
1
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' ;
3
3
import 'package:dialog_back_button/provider/app_state_manager_provider.dart' ;
4
4
import 'package:dialog_back_button/route/app_router_util.dart' ;
5
5
import 'package:dialog_back_button/route/index.dart' ;
6
6
import 'package:dialog_back_button/util/page_util.dart' ;
7
7
import 'package:flutter/material.dart' ;
8
-
9
8
class OnePage extends StatefulWidget {
10
9
@override
11
10
State <StatefulWidget > createState () {
@@ -25,12 +24,39 @@ class _OnePageState extends State<OnePage> {
25
24
26
25
Widget _buildBody () {
27
26
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
+ ],
34
60
),
35
61
);
36
62
}
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change @@ -32,32 +32,6 @@ class _TwoPageState extends State<TwoPage> {
32
32
);
33
33
}
34
34
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
-
61
35
Future <bool > _onBackPressed () async {
62
36
var result = await showDialog <bool >(
63
37
context: context,
Original file line number Diff line number Diff line change @@ -4,6 +4,8 @@ import 'index.dart';
4
4
5
5
const String onePath = '/one' ;
6
6
const String twoPath = '/two' ;
7
+ const String threePath = '/three' ;
8
+ const String fourPath = "/four" ;
7
9
8
10
class PageConfiguration {
9
11
final String key;
You can’t perform that action at this time.
0 commit comments