Get.to(MyPage()) - How to remove all previous routes - Flutter GetX

Viewed 26234

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

6 Answers

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

Use Get.reset() this will remove all the previous routes

for removing last page:

Get.off(()=>PageName());

for clearing all previous pages:

Get.offAll(()=>PageName());

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);

Try this:

 Get.offNamedUntil('home', (route) => false);
Related