'How To Prevent Navigation Loops In Flutter
In my application I have 13 screens in total, some of them has links to other screens, I also have a drawer that has links to most of these screens.
The following image shows the only navigation flow that I want in the app:
as you can see the only screens that have links to other screens are the home
, warehouses
and close expiry
screens. But because the drawer exists in every screen I now can navigate from warehouses
to products
then warehouses
then products
and so on, or from close expiry
to warehouses
to products
to home
to close expiry
until the end of time.
what I want is this: whenever the user navigates to one of the home
screen direct links, the screens stack should only contain the home
screen and the navigated to screen with it's descendants.
In other words, I want to make sure the the screens stack has only one instance of any screen in the app. I don't want loops, and I also don't want to get rid of the drawer.
Is there any way to achieve that?
Thanks in advance.
Solution 1:[1]
The only way that I've found is to always navigate to the home screen before going to any other screen, this way we can achieve exactly what is asked in the question
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Bakri Alkhateeb |