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.
CodePudding user response:
You can define your drawer in a separate widget file, that you can import everywhere you have a scafold.
CodePudding user response:
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
CodePudding user response:
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()
.