Reputation: 654
If the user clicks on back from homepage, he should go to product details page.
When I am using Get.tonamed(Routes.Home) , Getx is creating a new instance of homepage.
If I remove pages in stack and go back to homepage, I am not able to take user to the details page wien the user presses the back button.
I want to take user to details page when he clicks on back button.
Upvotes: 0
Views: 1242
Reputation: 25050
Use Get.ofAll(Home());
to avoid creating new instance of HomePage
this will remove all the stacked pages in the Navigation Stack
When you go from Home -> Products -> Details -> Home.
Navigator creates a stack, so that you can go back to the top of the stack when a page is popped
| Home | 👈 Top of the stack
| Details |
| Products |
| Home |
|__________|
Home
?To access the Home you have to pop all the elements in the stack and reach Home
1.Popping Details Screen
_> Pop Details Page from the stack
| ( |
| Details |
| Products |
| Home |
|__________|
2.Popping Products Screen
_> Pop Products Page from the stack
| ( |
| Products |
| Home |
|__________|
Now the stack:
| |
| Home | 👈 Top of the stack
|__________|
Details Page
now ?No, you cannot go back to DetailsPage
because you have popped the DetailsPage
,ProductsPage
to reach Home
Upvotes: 1
Reputation: 39
On tap in PRODUCTS DETAILS PAGE please do like this:
Get.offAll(HomePage());
Upvotes: 0
Reputation: 1557
You need to pop/Back screens till home page from Navigation stack
instead of adding it again in navigation stack.In your current code you are again adding home page in Navigation stack from product details page.
so you need to use offAll
or offNamedUntil
avoid new instance of home page you need pop/back screen until home screen.avoid
It will remove all previous pages from navigation stack.
Get.offAll(Home());
// OR. //
Get.offNamedUntil('home', (route) => false); // RouteName
For more information checkout this link
Official package check Readme Route management
link
Upvotes: 0