Reputation: 4800
I have a simple Flutter app and I want to remove all previous routes but I want to do with GetX, How to do that?
Now it works with
Navigator.of(context).pushNamedAndRemoveUntil('/home', (Route<dynamic> route) => false);
But I want to know the correct way with Get.to
or similar
Upvotes: 19
Views: 62655
Reputation: 151
for removing last page:
Get.off(()=>PageName());
for clearing all previous pages:
Get.offAll(()=>PageName());
Upvotes: 12
Reputation: 41
Try this:
Get.offNamedUntil('home', (route) => false);
Upvotes: 3
Reputation: 2786
If you want remove last page then use it.
Get.off(Home());
If you want remove all previous page then use it.
Get.offAll(Home());
just simple
Upvotes: 26
Reputation: 2227
Get.offAll(Home());
of with namedRoutes:
Get.offAllNamed('/home');
More info on docs: https://github.com/jonataslaw/getx/blob/master/documentation/en_US/route_management.md
Upvotes: 49
Reputation: 7640
You are looking for Get.reset();
. Please check this 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);
Upvotes: 1