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.
3
Answers
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
oroffNamedUntil
avoid new instance of home page you need pop/back screen until home screen.avoidIt will remove all previous pages from navigation stack.
For more information checkout this link
Official package check Readme
Route management
linkUse
Get.ofAll(Home());
to avoid creating new instance ofHomePage
this will remove all the stacked pages in the Navigation StackExplanation:
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
What if i want only one instance of
Home
?To access the Home you have to pop all the elements in the stack and reach
Home
1.Popping Details Screen
2.Popping Products Screen
Now the stack:
Is it possible to go back to the
Details Page
now ?No, you cannot go back to
DetailsPage
because you have popped theDetailsPage
,ProductsPage
to reachHome
On tap in PRODUCTS DETAILS PAGE please do like this: