withPoppedRoute method
- AppRoute route
Returns a copy of the app route state but with the given route removed if it is in the route stack
Unlike toPopped, the currently selected appRootRoute or current will not change (unless the current is a RootAppRoute that was popped).
The given route can be ancestor in the appRoutes or current stack;
The entire stack will point to the parent of the route in this case,
popping several routes at once.
If the given route is not in the appRoutes or current stack at all,
this method will effectively return the current route state as is.
Implementation
AppRouteState withPoppedRoute(AppRoute route) {
final appRootRoute = AppRootRoute.forAppRoute(route);
var parent = _getParent(route) ?? appRootRoute?.appRoute;
FleetView? fleetView;
bool? fleetShowingDashboard;
if (parent is FleetRoute) {
fleetView = parent.view;
fleetShowingDashboard = parent.showingDashboard;
parent = AppRoute.fleet;
}
final appRoute = appRoutes[appRootRoute];
final isInAppRoute = appRoute != null &&
appRoute.expandAncestors((a) => [a]).contains(route);
final isInCurrent =
current != null && current!.expandAncestors((a) => [a]).contains(route);
return AppRouteState(
appRoutes: {
...appRoutes,
if (appRootRoute != null && parent != null && isInAppRoute)
appRootRoute: parent,
},
appRootRoute: this.appRootRoute,
current: isInCurrent ? parent : current,
fleetView: fleetView ?? this.fleetView,
fleetShowingDashboard:
fleetShowingDashboard ?? this.fleetShowingDashboard,
);
}