16

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

Christopher Moore
  • 15,626
  • 10
  • 42
  • 52
Álvaro Agüero
  • 4,494
  • 1
  • 42
  • 39

6 Answers6

37
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

jonatas Borges
  • 1,947
  • 13
  • 17
19

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

Jewel Rana
  • 2,397
  • 1
  • 19
  • 28
6

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

Kaushik Kakdey
  • 599
  • 4
  • 10
6

for removing last page:

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

for clearing all previous pages:

Get.offAll(()=>PageName());
NeverSleeps
  • 1,439
  • 1
  • 11
  • 39
3

Try this:

 Get.offNamedUntil('home', (route) => false);
Majid Hajibaba
  • 3,105
  • 6
  • 23
  • 55
2

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);
Akif
  • 7,098
  • 7
  • 27
  • 53