Skip to content

Commit

Permalink
适配flutter 3.16.0 PopScope部分实现回退
Browse files Browse the repository at this point in the history
  • Loading branch information
simplezhli committed Nov 18, 2023
1 parent f49ad66 commit 333d690
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/flutter-web-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ name: flutter_deer web deploy
on:
push:
paths:
- 'pubspec.yaml'
- 'pubspec.yaml1'

jobs:
web_build_and_deploy:
Expand Down
2 changes: 1 addition & 1 deletion ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
5 changes: 3 additions & 2 deletions lib/mvp/base_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ mixin BasePageMixin<T extends StatefulWidget, P extends BasePresenter> 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(),
);
Expand Down
26 changes: 14 additions & 12 deletions lib/widgets/double_tap_back_exit_app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,21 @@ class _DoubleTapBackExitAppState extends State<DoubleTapBackExitApp> {

@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<bool> _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);
}
}

0 comments on commit 333d690

Please sign in to comment.