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

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



Solution 1:[1]

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

Solution 2:[2]

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

Solution 3:[3]

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

Solution 4:[4]

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

Solution 5:[5]

Try this:

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

Solution 6:[6]

for removing last page:

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

for clearing all previous pages:

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 jonatas Borges
Solution 2 Jewel Rana
Solution 3 Kaushik Kakdey
Solution 4 Akif
Solution 5 Majid Hajibaba
Solution 6 NeverSleeps