How To Prevent Navigation Loops In Flutter - 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.

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

Related

How to implement figma's smart animate option in flutter?

I designed three onboarding pages in figma which contains information about my app, while wireframing the app, I added smart animate to the three pagesThis is the first onboarding page
The second one
The third one
The smart animate enables smooth transition from each page to each page
While using flutter, I created 3 different pages for each onboarding pages and added a navigation widget to each button
But the navigation from each page to each page was stacked
I also tried using gesturedetection() onhorizontalswipe still same result
The pages navigate in a stacked way totally different from figma's smart animate option.
Is there anyway I can do this?
I'll appreciate any help
Thanks in advance.
From what I understood,
You want to build an onboarding screen with some animation. But the pages are being stacked.
It is happening because you are navigating to different pages with each button press. That is very bad practice for building an onboarding screen.
You should be using a PageView widget that allows you to transit between pages without navigating to them.
If you want to use a plugin that suits you, I would recommend introduction_screen

How do you create a side navigation drawer that persists across pages?

I've looked through many tutorials for the side nav drawer. I can create one that works fine to lead to different pages. However, when I travel to a page that's different from home, it only gives me the arrow icon to go back to home at the top left instead of keeping the button to bring me back to the side navbar. How can I prevent this?
I can't use the home page to navigate everywhere because it's just supposed to be a blank splash screen.
You can define your drawer in a separate widget file, that you can import everywhere you have a scafold.
I created a package for it because I was missing similar functionality. If you want a Flutter approach for this navigation check out: https://api.flutter.dev/flutter/material/NavigationRail-class.html
Or if you want to have a look at my package: https://pub.dev/packages/side_navigation
It's because you're moving to a new page/Scaffold (probably using Navigator.push()). So, the default button in the AppBar will be the back button.
You can either have the same Drawer in every Scaffold you navigate to, which is not recommended since you'll just keep pushing routes to the navigation stack.
Or, you can change pages within the Scaffold. Check the interactive examples in BottomNavigationBar and NavigationRail to get an idea of how to do it. Basically instead of calling Navigator.push() when a tile in Drawer is tapped, just update the selected index and call setState().

How to navigate to a specific Route at app start and show another one when popping in Flutter?

The question is, how to achieve this with a clean navigation approach in Flutter.
So to better understand the question, here's an example:
The user taps on a messenger notification and the app opens. The first screen to show is a setup screen, which verifies if the user authenticated and does some app related stuff. The next screen should be the chat with the corresponding message. After closing this chat screen, the user lands on the screen containing a list with all chats. After closing this one, the user lands on the home screen of the app.
What is the best and cleanest approach to handle such a scenario? Should I use a separate navigation package like auto_route or what do u suggest?
Or is this a deep link scenario? How to implement such a scenario?
Define static String id for all screen,after define them under MaterialApp as
routes (map<Sting, Function>) after you have to give parameter to initial route still under MaterialApp, now you can use these routes by using Navigator.pushNaned and Navigator.pop function.

HOW I CAN MAKE TAB SCREE LIKE THAT IN FLUTTER

I want to make screen like that using flutter. The screen must have 2 tabs .both tab screens load on same main screen Eg. when user click tab one on screen load tab one ( as the photo) and click Tab 2 on screen load tab 2. How I can do that code
You need to use PageView() to show more than one page at the same place.
you need to pass to de PageView() the controller (which is a widget of PageController)
so you can call the pageController.animateToPage() so you can animate and switch between pages...
you can find how to use the PageView here, they explain really well!
hope that helped!

How to distribute state of BottomNavigationBar across the app in Flutter?

In my app, the navigation bar works fine between the tabs, but when I go inside of each item in my list, I want the navigation bar to be there too.
What I did is that I made it a separate widget, and called in the bottomNavigationBar inside the Scaffold of the pages, but the problem is that I am changing the state of the navigation bar in my main page only, so the state doesn't get distributed across all pages in my app.
How do I make the body of the page change in an app where there is not only one body, but many?
Thanks!
Since there is not code over here in your post and I don't know what you have done so far so I can only advise you to go through this post.
I know you might have already seen this, but still, try to follow and this will really help.
Thanks....!!!!!!
https://medium.com/#lucassaltoncardinali/keeping-state-with-the-bottom-navigation-bar-in-flutter-69e4168878e1