skip to Main Content

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


  1. 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

    Login or Signup to reply.
  2. Use Get.ofAll(Home()); to avoid creating new instance of HomePage this will remove all the stacked pages in the Navigation Stack

    Explanation:

    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     |
    |__________|
    

    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

          _>  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
    |__________|
    

    Is it possible to go back to the Details Page now ?

    No, you cannot go back to DetailsPage because you have popped the DetailsPage,ProductsPage to reach Home

    Login or Signup to reply.
  3. On tap in PRODUCTS DETAILS PAGE please do like this:

    Get.offAll(HomePage());
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search