I don't use named routes in the app. Instead followed by the inspiration from FlutterBloc library I use route definitions like this.
class OrganizationPage extends StatelessWidget {
static Route route() {
return MaterialPageRoute<void>(builder: (_) => OrganizationPage());
}
// ....
}
And I navigate using...
Navigator.push(
context,
LoginPage.route(),
);
Assume from the point of loading the OrganizationPage I have navigated few times. I want a button press that will pop OrganizationPage route + every thing else on top of it and load a new page. How can this be done?
I thought of doing some thing like this...
Navigator.pushAndRemoveUntil(
context,
HomePage.route(),
(Route<dynamic> route) {
// print("Checking route: $route");
// return route.builder.toString().contains("OrganizationPage")
// `builder` is not available, even though it did in the debugger.
},
);
Can what I want be done? If so how?
I assume if I use named routes it might be easier? Unfortunately I have written a lot of code and prefer to avoid a refactor. Also this way I can accept any args to a page easily.
Thanks in advance.