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

54.6k views Asked by At

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

There are 6 answers

0
Akif On

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);
0
jonatas Borges On
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

0
Pranesh Pyara Shrestha On

for removing last page:

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

for clearing all previous pages:

Get.offAll(()=>PageName());
0
Jorge Alejandro Rodriguez Ovie On

Try this:

 Get.offNamedUntil('home', (route) => false);
0
Kaushik Kakdey On

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

0
Jewel Rana On

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