From 333d6909b1070fb554dd5a1c5db705c531a40251 Mon Sep 17 00:00:00 2001 From: weilu Date: Sat, 18 Nov 2023 08:53:35 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=82=E9=85=8Dflutter=203.16.0=20PopScope?= =?UTF-8?q?=E9=83=A8=E5=88=86=E5=AE=9E=E7=8E=B0=E5=9B=9E=E9=80=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/flutter-web-deploy.yml | 2 +- ios/Podfile | 2 +- lib/mvp/base_page.dart | 5 +++-- lib/widgets/double_tap_back_exit_app.dart | 26 ++++++++++++----------- 4 files changed, 19 insertions(+), 16 deletions(-) diff --git a/.github/workflows/flutter-web-deploy.yml b/.github/workflows/flutter-web-deploy.yml index 5829863eb..0e2e778c5 100644 --- a/.github/workflows/flutter-web-deploy.yml +++ b/.github/workflows/flutter-web-deploy.yml @@ -5,7 +5,7 @@ name: flutter_deer web deploy on: push: paths: - - 'pubspec.yaml' + - 'pubspec.yaml1' jobs: web_build_and_deploy: diff --git a/ios/Podfile b/ios/Podfile index 00d2e9470..73de607b0 100644 --- a/ios/Podfile +++ b/ios/Podfile @@ -2,7 +2,7 @@ platform :ios, '11.0' # source 'https://github.com/CocoaPods/Specs.git' -source 'https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git' +# source 'https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git' # CocoaPods analytics sends network stats synchronously affecting flutter build latency. ENV['COCOAPODS_DISABLE_STATS'] = 'true' diff --git a/lib/mvp/base_page.dart b/lib/mvp/base_page.dart index 3cd10ef2f..20b95f76c 100644 --- a/lib/mvp/base_page.dart +++ b/lib/mvp/base_page.dart @@ -38,10 +38,11 @@ mixin BasePageMixin on State< barrierDismissible: false, barrierColor: const Color(0x00FFFFFF), // 默认dialog背景色为半透明黑色,这里修改为透明(1.20添加属性) builder:(_) { - return PopScope( - onPopInvoked: (_) { + return WillPopScope( + onWillPop: () async { // 拦截到返回键,证明dialog被手动关闭 _isShowDialog = false; + return Future.value(true); }, child: buildProgress(), ); diff --git a/lib/widgets/double_tap_back_exit_app.dart b/lib/widgets/double_tap_back_exit_app.dart index d24bfe807..5adfaf860 100644 --- a/lib/widgets/double_tap_back_exit_app.dart +++ b/lib/widgets/double_tap_back_exit_app.dart @@ -25,19 +25,21 @@ class _DoubleTapBackExitAppState extends State { @override Widget build(BuildContext context) { - return PopScope( - canPop: _lastTime == null || DateTime.now().difference(_lastTime!) > widget.duration, - onPopInvoked: (didPop) { - if (!didPop) { - Toast.cancelToast(); - /// 不推荐使用 `dart:io` 的 exit(0) - SystemNavigator.pop(); - } else { - _lastTime = DateTime.now(); - Toast.show('再次点击退出应用'); - } - }, + return WillPopScope( + onWillPop: _isExit, child: widget.child, ); } + + Future _isExit() async { + if (_lastTime == null || DateTime.now().difference(_lastTime!) > widget.duration) { + _lastTime = DateTime.now(); + Toast.show('再次点击退出应用'); + return Future.value(false); + } + Toast.cancelToast(); + /// 不推荐使用 `dart:io` 的 exit(0) + await SystemNavigator.pop(); + return Future.value(true); + } }