pushReplacementAll method
Replace last route with new routes with push animation
Implementation
void pushReplacementAll(List<NavRouteInfo> routeInfos) {
try {
final context = _currentContext;
if (context == null) {
if (_enableLogger) {
debugPrint('NavService.pushReplacementAll: No valid context found.');
}
return;
}
final navigator = Navigator.of(context);
final currentIndex = _steps.length - 1;
if (currentIndex > 0) {
// Remove last existing route
if (_steps.isNotEmpty) {
final lastStep = _steps.last;
if (lastStep.currentRoute.isActive) {
navigator.removeRoute(lastStep.currentRoute);
}
}
// Push new routes
pushAll(routeInfos);
} else {
// Ensure remove all navigation history
// Push first route with or without animation
final firstRouteInfo = routeInfos.first;
final firstRoute = _routes[firstRouteInfo.path];
if (firstRoute == null) {
if (_enableLogger) {
debugPrint(
'NavService.pushReplacementAll: Route not found for path: '
'${firstRouteInfo.path}',
);
}
} else {
navigator.pushAndRemoveUntil(
_buildPageRouteNoPushAnimation(
path: firstRouteInfo.path,
extra: NavExtra(firstRouteInfo.extra ?? {}),
route: firstRoute,
),
(route) => false,
);
}
// Push remaining routes in order with animation at last
final remainingRouteInfos = routeInfos.sublist(1);
pushAll(remainingRouteInfos);
}
// ignore: avoid_catches_without_on_clauses
} catch (e, st) {
if (_enableLogger) {
debugPrint('NavService.pushReplacementAll.exception: $e\n$st');
}
}
}