Skip to content

Commit

Permalink
optimize route monitor #162
Browse files Browse the repository at this point in the history
  • Loading branch information
xdd666t committed Dec 9, 2023
1 parent 088b101 commit 0466070
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
18 changes: 16 additions & 2 deletions lib/src/helper/navigator_observer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,29 @@ class SmartNavigatorObserver extends NavigatorObserver {
}

@override
void didReplace({Route<dynamic>? newRoute, Route<dynamic>? oldRoute}) {}
void didReplace({Route<dynamic>? newRoute, Route<dynamic>? oldRoute}) {
RouteRecord.curRoute = newRoute;
RouteRecord.instance.replace(newRoute: newRoute, oldRoute: oldRoute);
_removeDialog(oldRoute);
}

@override
void didRemove(Route<dynamic> route, Route<dynamic>? previousRoute) {}
void didRemove(Route<dynamic> route, Route<dynamic>? previousRoute) {
RouteRecord.instance.remove(route);
_removeDialog(route);
}

@override
void didPop(Route<dynamic> route, Route<dynamic>? previousRoute) async {
RouteRecord.curRoute = previousRoute;
RouteRecord.instance.pop(route, previousRoute);
_removeDialog(route);
}

void _removeDialog(Route<dynamic>? route) {
if (route == null) {
return;
}

var checkDialog = SmartDialog.config.checkExist(dialogTypes: {
SmartAllDialogType.custom,
Expand Down
13 changes: 13 additions & 0 deletions lib/src/helper/route_record.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,25 @@ class RouteRecord {
routeQueue.add(route);
}

void replace({Route<dynamic>? newRoute, Route<dynamic>? oldRoute}) {
if (DialogProxy.instance.dialogQueue.isEmpty) return;
routeQueue.remove(oldRoute);
if (newRoute != null) {
routeQueue.add(newRoute);
}
}

void pop(Route<dynamic> route, Route<dynamic>? previousRoute) {
_appearDialog(route, previousRoute);
if (routeQueue.isEmpty) return;
routeQueue.remove(route);
}

void remove(Route<dynamic> route) {
if (routeQueue.isEmpty) return;
routeQueue.remove(route);
}

/// curRoute: 当前可见的路由 nextRoute: 下一路由
void _hideDialog(Route<dynamic>? curRoute, Route<dynamic> nextRoute) {
if (_banContinue(nextRoute)) return;
Expand Down

0 comments on commit 0466070

Please sign in to comment.