Get.until((route) => !Get.isDialogOpen);
但我想知道是否可以在路由历史记录中包含特定页面实例的情况下关闭路由,大致代码如下:
Get.until((route) => !Get.routingHistory.contains('/someRoute'));
请注意,这不是有效的语法。
Get.until((route) => !Get.isDialogOpen);
但我想知道是否可以在路由历史记录中包含特定页面实例的情况下关闭路由,大致代码如下:
Get.until((route) => !Get.routingHistory.contains('/someRoute'));
Get.until 在满足条件之前移除屏幕。 它与Navigation.popUntil()相同。 您可以这样使用它:Get.until((route) => Get.currentRoute == '/home')。
Get.offNamed 通过命名路由,删除当前屏幕并添加新屏幕。 它与Navigation.pushReplacementNamed()相同。 您可以这样使用它:Get.offNamed('/second')。
Get.offAndToNamed 通过命名路由,先添加新屏幕,然后删除以前的屏幕。 它与Navigation.popAndPushNamed()相同。 您可以这样使用它:Get.offAndToNamed('/second')。
Get.offUntil 移除屏幕直到满足条件,然后添加一个新屏幕。 它与Navigation.pushAndRemoveUntil()相同。 您可以这样使用它:Get.offUntil(page, (route) => (route as GetPageRoute).routeName == '/home')。
Get.offNamedUntil 通过命名路由,移除屏幕直到满足条件,然后添加新屏幕。 它与Navigation.pushNamedAndRemoveUntil()相同。 您可以这样使用它:Get.offNamedUntil(page, ModalRoute.withName('/home'))。
请根据您的用例使用。
你需要使用:
Get.offUntil(page, (route) => false)
page 表示要导航到的新页面。
(route) => false
这是一个条件语句。
GetX还有另一个有用的功能:
int times = 2;
Get.close(times);
根据[times]的定义关闭尽可能多的路由
Navigator.of(context).popUntil(ModalRoute.withName('/route-name'));
It is possible. Navigator.popUntil pops pages until a passed predicate returns true. We can query the following route in the navigator stack and decide what decision to make.
The GetX method for doing the same is
`
Get.offUntil( MaterialPageRoute(builder: (context) => const NewPage()), (route) {
var currentRoute = route.settings.name;
debugPrint("Get.currentRoute --- $currentRoute");
if(currentRoute == "/Home") {
return true;
} else {
return false;
}
}
`
The code above pops until home. Also, we can add custom logic in the if-else block above.
Get.until((route) {
if (route.settings.name == Routes.TEST1) {
//Return to the specified page
return true;
} else {
return false;
}
});
Get.offAll(Home()); // remove all previous routes and redirect to home
关于namedRoutes的使用:
Get.offAllNamed('/home');