Using Navigator.popUntil and route without fixed name
You should add a setting when pushing your route; with a custom name
Navigator.pushReplacement(
context,
MaterialPageRoute(
settings: RouteSettings(name: "Foo"),
builder: ...,
),
);
Then you can use popUntil
as you'd do with named routes
Navigator.popUntil(context, ModalRoute.withName("Foo"))
If you do not use named routes or we want to the navigator to First active, you can use
Navigator.of(context).popUntil((route) => route.isFirst)