offAllNamed<T> method
Navigation.pushNamedAndRemoveUntil() shortcut.
Push a named page
and pop several pages in the stack
until predicate
returns true. predicate
is optional
It has the advantage of not needing context, so you can call from your business logic.
You can send any type of value to the other route in the arguments
.
predicate
can be used like this:
Get.until((route) => Get.currentRoute == '/home')
so when you get to home page,
or also like
Get.until((route) => !Get.isDialogOpen())
, to make sure the dialog
is closed
id
is for when you are using nested navigation,
as explained in documentation
Note: Always put a slash on the route ('/page1'), to avoid unexpected errors
Implementation
Future<T?>? offAllNamed<T>(
String newRouteName, {
RoutePredicate? predicate,
dynamic arguments,
int? id,
Map<String, String>? parameters,
}) {
if (parameters != null) {
final uri = Uri(path: newRouteName, queryParameters: parameters);
newRouteName = uri.toString();
}
return global(id).currentState?.pushNamedAndRemoveUntil<T>(
newRouteName,
predicate ?? (_) => false,
arguments: arguments,
);
}