Skip to content

Commit

Permalink
optimize BoostRouteMonitor #248
Browse files Browse the repository at this point in the history
  • Loading branch information
xdd666t committed Feb 8, 2025
1 parent 5722db8 commit bcd7088
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* Delete SmartConfigCustom/SmartConfigAttach/SmartConfigLoading backDismiss
* Add AdjustBuilder
* Fix [#229](https://github.com/fluttercandies/flutter_smart_dialog/issues/229), [#235](https://github.com/fluttercandies/flutter_smart_dialog/issues/235)
* Fix [#248](https://github.com/fluttercandies/flutter_smart_dialog/issues/248)

* # [4.9.7+x]
* optimize bindWidget, when bindWidget is not null, bindPage will be automatically set to false.
Expand Down
12 changes: 3 additions & 9 deletions lib/src/helper/pop_monitor/boost_route_monitor.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:flutter/material.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:flutter_smart_dialog/src/helper/dialog_proxy.dart';
import 'package:flutter_smart_dialog/src/kit/log.dart';
import 'package:flutter_smart_dialog/src/kit/view_utils.dart';
Expand Down Expand Up @@ -35,15 +34,10 @@ class BoostRouteMonitor {
}

if (route is ModalRoute) {
// WillPopCallback 该回调函数返回一个 Future<bool>
// 如果返回 true,则允许返回操作;如果返回 false,则阻止返回操作
willPopCallback() async {
if (MonitorPopRoute.handleSmartDialog()) {
DialogProxy.instance.dismiss(
status: SmartStatus.smart,
closeType: CloseType.back,
);
return false;
}
return true;
return !(await MonitorPopRoute.handBackEvent());
}

// TODO: `addScopedWillPopCallback()` was deprecated after v3.12.0-1.0.pre.
Expand Down
8 changes: 7 additions & 1 deletion lib/src/helper/pop_monitor/monitor_pop_route.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ class MonitorPopRoute with WidgetsBindingObserver {

@override
Future<bool> didPopRoute() async {
return MonitorPopRoute.handBackEvent();
}

// 返回出true, 表示当前已处理, 需要拦截
// 返回出false, 表示当前无需处理, 无需拦截
static Future<bool> handBackEvent() async {
//loading
if (SmartDialog.config.loading.isExist) {
final loadingInfo = DialogProxy.instance.loadingInfo;
Expand Down Expand Up @@ -75,7 +81,7 @@ class MonitorPopRoute with WidgetsBindingObserver {
}
}

return super.didPopRoute();
return false;
}

static bool handleSmartDialog() {
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description:
An elegant Flutter Dialog solution,
Easily implement Toast, Loading and custom Dialog,
Make the use of the dialog easier!
version: 4.9.8+5
version: 4.9.8+6
homepage: https://github.com/fluttercandies/flutter_smart_dialog
# flutter pub publish --server=https://pub.dartlang.org
# flutter build web --release --base-href="/flutter_smart_dialog/web/"
Expand Down

0 comments on commit bcd7088

Please sign in to comment.