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

6

19

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

Nadeen answered 16/10, 2020 at 20:37 Comment(0)
E
47
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

Edmead answered 18/10, 2020 at 6:9 Comment(0)
F
25

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

Flapjack answered 4/11, 2020 at 17:14 Comment(0)
C
11

for removing last page:

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

for clearing all previous pages:

Get.offAll(()=>PageName());
Cyn answered 25/4, 2022 at 10:10 Comment(0)
M
5

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

Mcgruter answered 6/11, 2020 at 7:30 Comment(1)
This will actually delete a GetxService, not only the routes.Scapula
B
3

Try this:

 Get.offNamedUntil('home', (route) => false);
Bradshaw answered 4/6, 2021 at 20:34 Comment(0)
T
1

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);
Tripartite answered 16/10, 2020 at 21:11 Comment(1)
This will actually delete a GetxService, not only the routes.Scapula

© 2022 - 2024 — McMap. All rights reserved.