Working with Flutter Drawer Outside of main.dart
Most of the Flutter examples IMHO just put the widgets all in the same file, which isn’t really realistic and don’t show how you would have to actually extract the widgets into separate files which I believe is a best practice.
It took me a while to find an appropriate example and even when I did, I felt that the example did not properly explain the difference between pushing a new PageWidget and replacing the PageWidget when structuring the navigation stack for an application.
My approach is to always “pushReplacement” when selecting an item from the Drawer and “push” when changing from one page to another.
In my sample application I have a list widget which when tapping on an item, it takes you to a specific detail page. Here since I want to maintain the navigation stack, I will not replace the current page in the stack with the next page, I will “push” the page widget to the stack.
I am just getting started with Flutter so I am still trying to figure things out, please let me know if there is something incorrect or if this is able to help you out with working with Drawers in Flutter.
See Full Source Code Here: https://github.com/aaronksaunders/flutter_drawer_detail