Navigation drawer is a UI panel which shows your app's main navigation menu. The navigation drawer appears when the user touches the interface icon in the app bar or when the user swipes a finger from the left edge on the screen. The navigation drawer slides show from the left and contain the navigation destinations for your app. You can see a complete description of navigation drawer Here. Before that we have been discussing about Face Detection In Flutter With MLKit And Firebase. Now, we will discuss how to create a navigation drawer in Flutter. Let's practice creating a menu drawer in flutter.
First, we must create new a project using Visual Studio Code software. Here's how to create a new project using Visual Studio Code:
Edit file pubspec.yaml in your directory and it should look something like the below:
  1. name: navigation_drawer
  2. description: A new Flutter project.
  3. # The following defines the version and build number for your application.
  4. # A version number is three numbers separated by dots, like 1.2.43
  5. # followed by an optional build number separated by a +.
  6. # Both the version and the builder number may be overridden in flutter
  7. # build by specifying --build-name and --build-number, respectively.
  8. # In Android, build-name is used as versionName while build-number used as versionCode.
  9. # Read more about Android versioning at https://developer.android.com/studio/publish/versioning
  10. # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
  11. # Read more about iOS versioning at
  12. # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
  13. version: 1.0.0+1
  14. environment:
  15. sdk: ">=2.1.0 <3.0.0"
  16. dependencies:
  17. flutter:
  18. sdk: flutter
  19. # The following adds the Cupertino Icons font to your application.
  20. # Use with the CupertinoIcons class for iOS style icons.
  21. cupertino_icons: ^0.1.2
  22. dev_dependencies:
  23. flutter_test:
  24. sdk: flutter
  25. # For information on the generic Dart part of this file, see the
  26. # following page: https://www.dartlang.org/tools/pub/pubspec
  27. # The following section is specific to Flutter.
  28. flutter:
  29. # The following line ensures that the Material Icons font is
  30. # included with your application, so that you can use the icons in
  31. # the material Icons class.
  32. uses-material-design: true
  33. # To add assets to your application, add an assets section, like this:
  34. assets:
  35. - assets/camellab.png
  36. # - images/a_dot_burr.jpeg
  37. # - images/a_dot_ham.jpeg
  38. # An image asset can refer to one or more resolution-specific "variants", see
  39. # https://flutter.io/assets-and-images/#resolution-aware.
  40. # For details regarding adding assets from package dependencies, see
  41. # https://flutter.io/assets-and-images/#from-packages
  42. # To add custom fonts to your application, add a fonts section here,
  43. # in this "flutter" section. Each entry in this list should have a
  44. # "family" key with the font family name, and a "fonts" key with a
  45. # list giving the asset and other descriptors for the font. For
  46. # example:
  47. # fonts:
  48. # - family: Schyler
  49. # fonts:
  50. # - asset: fonts/Schyler-Regular.ttf
  51. # - asset: fonts/Schyler-Italic.ttf
  52. # style: italic
  53. # - family: Trajan Pro
  54. # fonts:
  55. # - asset: fonts/TrajanPro.ttf
  56. # - asset: fonts/TrajanPro_Bold.ttf
  57. # weight: 700
  58. #
  59. # For details regarding fonts from package dependencies,
  60. # see https://flutter.io/custom-fonts/#from-packages

Modify file main.dart to completed like below,
  1. import 'package:flutter/material.dart';
  2. void main() => runApp(MyApp());
  3. class MyApp extends StatelessWidget {
  4. final appTitle = 'Camellabs Demo';
  5. @override
  6. Widget build(BuildContext context) {
  7. return MaterialApp(
  8. title: appTitle,
  9. home: MyHomePage(title: appTitle),
  10. );
  11. }
  12. }
  13. class MyHomePage extends StatelessWidget {
  14. final String title;
  15. MyHomePage({Key key, this.title}) : super(key: key);
  16. @override
  17. Widget build(BuildContext context) {
  18. return Scaffold(
  19. appBar: AppBar(title: Text(title)),
  20. body: Center(child: Text('My Page!')),
  21. drawer: Drawer(
  22. // Add a ListView to the drawer. This ensures the user can scroll
  23. // through the options in the Drawer if there isn't enough vertical
  24. // space to fit everything.
  25. child: ListView(
  26. // Important: Remove any padding from the ListView.
  27. padding: EdgeInsets.zero,
  28. children: <Widget>[
  29. DrawerHeader(
  30. child: Text(
  31. 'Drawer Header',
  32. style: TextStyle(color: Colors.white, fontSize: 22),),
  33. decoration: BoxDecoration(
  34. color: Colors.lightBlue[300],
  35. ),
  36. ),
  37. ListTile(
  38. title: Text('Menu 1', style: TextStyle(color: Colors.deepOrange),),
  39. onTap: () {
  40. // Update the state of the app
  41. // ...
  42. // Then close the drawer
  43. Navigator.push(
  44. context,
  45. MaterialPageRoute(builder: (context) => Menu1Page()),
  46. );
  47. },
  48. ),
  49. ListTile(
  50. title: Text('Menu 2', style: TextStyle(color: Colors.deepOrange),),
  51. onTap: () {
  52. // Update the state of the app
  53. // ...
  54. // Then close the drawer
  55. Navigator.push(
  56. context,
  57. MaterialPageRoute(builder: (context) => Menu2Page()),
  58. );
  59. },
  60. ),
  61. ],
  62. ),
  63. ),
  64. );
  65. }
  66. }
  67. class Menu1Page extends StatelessWidget {
  68. @override
  69. Widget build(BuildContext context) {
  70. return Scaffold(
  71. appBar: AppBar(
  72. title: Text("Menu 1 Page"),
  73. ),
  74. body: Center(
  75. child: RaisedButton(
  76. onPressed: () {
  77. Navigator.pop(context);
  78. },
  79. child: Text('Go back!'),
  80. ),
  81. ),
  82. );
  83. }
  84. }
  85. class Menu2Page extends StatelessWidget {
  86. @override
  87. Widget build(BuildContext context) {
  88. return Scaffold(
  89. appBar: AppBar(
  90. title: Text("Menu 2 Page"),
  91. ),
  92. body: Center(
  93. child: RaisedButton(
  94. onPressed: () {
  95. Navigator.pop(context);
  96. },
  97. child: Text('Go back!'),
  98. ),
  99. ),
  100. );
  101. }
  102. }

After you have finished copying the main.dart code, running the application will show the below output:
Create Navigation Drawer In Flutter
You can see a navigation drawer in Flutter example Here.
Thank you for reading this article about creating navigation drawer in Flutter, I hope this article is useful for you. Visit My Github about Flutter Here.