Álvaro Agüero
Álvaro Agüero

Reputation: 4800

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

Upvotes: 19

Views: 62655

Answers (6)

Pranesh Pyara Shrestha
Pranesh Pyara Shrestha

Reputation: 151

for removing last page:

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

for clearing all previous pages:

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

Upvotes: 12

Try this:

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

Upvotes: 3

Kaushik Kakdey
Kaushik Kakdey

Reputation: 673

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

Upvotes: 5

Jewel Rana
Jewel Rana

Reputation: 2786

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

Upvotes: 26

jonatas Borges
jonatas Borges

Reputation: 2227

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

Upvotes: 49

Akif
Akif

Reputation: 7640

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

Upvotes: 1

Related Questions