1- import 'dart:ui' ;
21import 'package:flutter/foundation.dart' ;
32import 'package:flutter/material.dart' ;
43import 'package:fluttertoast/fluttertoast.dart' ;
@@ -11,7 +10,7 @@ void main() {
1110}
1211
1312class MyApp extends StatefulWidget {
14- const MyApp ({Key ? key}) : super ( key: key );
13+ const MyApp ({super . key} );
1514
1615 @override
1716 State <MyApp > createState () => _MyAppState ();
@@ -26,7 +25,7 @@ class _MyAppState extends State<MyApp> {
2625
2726 Widget getDefaultRouter () {
2827 //还记得我们上边的routerPage嘛, 这个东西就是我们传进来的字符串,我们可以根据这个字符串来决定加载那个flutter页面
29- String router = window .defaultRouteName;
28+ String router = PlatformDispatcher .instance .defaultRouteName;
3029 if (kDebugMode) {
3130 print ("获取到路由数据--------$router " );
3231 }
@@ -44,19 +43,21 @@ class _MyAppState extends State<MyApp> {
4443
4544 @override
4645 Widget build (BuildContext context) {
47- return WillPopScope (
48- onWillPop: () {
49- // 退出APP方法一
50- Fluttertoast .showToast (
51- msg: '您确定要退出思预云吗?' ,
52- toastLength: Toast .LENGTH_SHORT ,
53- gravity: ToastGravity .CENTER ,
54- timeInSecForIosWeb: 1 ,
55- backgroundColor: Colors .red,
56- textColor: Colors .white,
57- fontSize: 16.0 );
58- return Future .value (false );
59- }, // look here!
46+ return PopScope (
47+ canPop: false ,
48+ onPopInvokedWithResult: (didPop, result) {
49+ // 退出APP方法二
50+ if (! didPop) {
51+ Fluttertoast .showToast (
52+ msg: '您确定要退出思预云吗?' ,
53+ toastLength: Toast .LENGTH_SHORT ,
54+ gravity: ToastGravity .CENTER ,
55+ timeInSecForIosWeb: 1 ,
56+ backgroundColor: Colors .red,
57+ textColor: Colors .white,
58+ fontSize: 16.0 );
59+ }
60+ },// look here!
6061 child: MaterialApp (
6162 home: getDefaultRouter (),
6263 routes: < String , WidgetBuilder > {
0 commit comments