I want to navigate to different Routes using a Drawer, though I do not want to open a new instance of a Route each time I tap on it if I am already on that Route, rather I would
This is my solution. Based on the Rémi Rousselet solution. The only difference is that prevent te pop of the "last" route remaining.
bool routeFound = false;
String routeName = "/myRoute";
//remove all the routes and stops if find the routeName or if is the last one
Navigator.popUntil(context, (route) {
if (route.settings.name == routeName) {
expenseRouteFound = true;
}
//print("route " + routeName + " founded in stack: " + routeFound.toString());
//print("last remaining route into the stack: " + route.isFirst.toString());
return routeFound || route.isFirst;
});
//print("route " + routeName + " founded in stack: " + routeFound.toString());
if (!routeFound) {
//print("time to push the route: " + routeName + "!");
Navigator.of(context).pushNamedAndRemoveUntil(routeName, (_)=>false);
}