【问题标题】:Get.to(MyPage()) - How to remove all previous routes - Flutter GetXGet.to(MyPage()) - 如何删除所有以前的路由 - Flutter GetX
【发布时间】:2021-01-31 09:15:33
【问题描述】:
我有一个简单的 Flutter 应用,我想删除所有以前的路由,但我想使用 GetX,怎么做?
现在可以使用了
Navigator.of(context).pushNamedAndRemoveUntil('/home', (Route<dynamic> route) => false);
但我想知道Get.to 或类似的正确方法
【问题讨论】:
标签:
flutter
dart
flutter-routes
flutter-getx
【解决方案1】:
您正在寻找Get.reset();。请检查此page。
/// Clears all registered instances (and/or tags).
/// Even the persistent ones.
///
/// - [clearFactory] clears the callbacks registered by [Get.lazyPut()]
/// - [clearRouteBindings] clears Instances associated with Routes when using
/// [GetMaterialApp].
bool reset({bool clearFactory = true, bool clearRouteBindings = true}) =>
GetInstance().reset(
clearFactory: clearFactory, clearRouteBindings: clearRouteBindings);
【解决方案3】:
如果要删除最后一页,请使用它。
Get.off(Home());
如果要删除所有以前的页面,请使用它。
Get.offAll(Home());
很简单
【解决方案5】:
试试这个:
Get.offNamedUntil('home', (route) => false);