getInnermostNamedNavigatorRoute static method
Gets the current navigator route, if that route has a name. If it doesn't have a name, it will go back until it finds a route with a name. This can be helpful if you are in a dialog or bottom sheet, and you want to know the route of the screen it's in.
Implementation
static Route? getInnermostNamedNavigatorRoute(BuildContext context) {
Route? currentRoute;
Navigator.popUntil(context, (Route<dynamic> route) {
currentRoute = route;
return (route.settings.name != null) && (route.settings.name!.isNotEmpty);
});
return currentRoute;
}