{"id":10642,"date":"2021-10-08T10:00:00","date_gmt":"2021-10-08T01:00:00","guid":{"rendered":"https:\/\/www.gigas-jp.com\/appnews\/?p=10642"},"modified":"2021-10-07T19:56:16","modified_gmt":"2021-10-07T10:56:16","slug":"flutter-navigation-drawer","status":"publish","type":"post","link":"https:\/\/www.gigas-jp.com\/appnews\/archives\/10642","title":{"rendered":"Flutter &#8211; Navigation drawer"},"content":{"rendered":"\n<p><strong>Output<\/strong>:<\/p>\n\n\n\n<div class=\"wp-block-columns\">\n<div class=\"wp-block-column\">\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" src=\"https:\/\/www.gigas-jp.com\/appnews\/wp-content\/uploads\/sites\/4\/2021\/10\/a.png\" alt=\"\" class=\"wp-image-10643\" width=\"181\" height=\"382\"\/><\/figure>\n<\/div>\n\n\n\n<div class=\"wp-block-column\">\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" src=\"https:\/\/www.gigas-jp.com\/appnews\/wp-content\/uploads\/sites\/4\/2021\/10\/b.png\" alt=\"\" class=\"wp-image-10644\" width=\"183\" height=\"386\"\/><\/figure>\n<\/div>\n<\/div>\n\n\n\n<p>This week I would like to share about navigation drawer from Drawer widget. We can create navigation drawer by calling the constructor of the drawer class. Drawer widgets show us navigation drawer that slides to horizontally from edge fo the screen. <\/p>\n\n\n\n<p>When we tap app bar, it will display the drawer. In this article we will create DrawerSection and eight navigation links. The links&nbsp;<strong>Dashboard<\/strong>,&nbsp;<strong>Contacts<\/strong>, <strong>Events<\/strong>, <strong>Notes<\/strong>, <strong>Settings<\/strong>, <strong>Notifications<\/strong>, <strong>Privacy policy <\/strong>and&nbsp;<strong>Send feedback<\/strong>&nbsp;are created using Column widget. Let\u2019s design the drawer part first. I am creating drawer widget named <strong>MyDrawerList<\/strong>. And I am creating other drawer in a separate file so that we can reuse it in other pages.<\/p>\n\n\n\n<p>Basic implementation of navigation drawer:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>MyDrawerList(\n        child:Column(\n\n         children: &#91;\n             menuItem(1, \"Dashboard\", Icons.dashboard_outlined,\n              currentPage == DrawerSections.dashboard ? true : false),\n             \n              menuItem(2, \"Contacts\", Icons.people_alt_outlined,\n              currentPage == DrawerSections.contacts ? true : false),\netc..\n\n          ],\n        ) ,\n   ),<\/code><\/pre>\n\n\n\n<p>At first dashboard page is wanted to see, we can assign <strong>currentPage<\/strong> to <strong>DrawerSection.dashboard<\/strong>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>var currentPage = DrawerSections.dashboard;<\/code><\/pre>\n\n\n\n<p>To display a navigation drawer we have to provide&nbsp;<strong>Drawer<\/strong>&nbsp;widget to scaffold\u2019s drawer property.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Scaffold(\n      appBar: AppBar(\n        backgroundColor: Colors.green&#91;700],\n        title: const Text(\"Navigation drawer\"),\n      ),\n      body: container,\n      drawer: Drawer(\n        child: SingleChildScrollView(\n          child: Column(\n            children: &#91;\n              const MyHeaderDrawer(),\n              MyDrawerList(),\n            ],\n          ),\n        ),\n      ),\n    );<\/code><\/pre>\n\n\n\n<p>If you want to navigate to another route first we have to dismiss the drawer by using below line of code<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> Navigator.pop(context);<\/code><\/pre>\n\n\n\n<p>Now we have to navigate to another route using&nbsp;<strong>menuItem<\/strong>&nbsp;like below, in above we assign current page to dashboard page and menuItem widget is called in <strong>MyDrawerList<\/strong> widget. <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Widget menuItem(int id, String title, IconData icon, bool selected) {\n    return Material(\n      color: selected ? Colors.grey&#91;300] : Colors.transparent,\n      child: InkWell(\n        onTap: () {\n          Navigator.pop(context);\n          setState(() {\n            if (id == 1) {\n              currentPage = DrawerSections.dashboard;\n            }\n        }\netc..\n}\n<\/code><\/pre>\n\n\n\n<p>Hope you enjoyed this post.<\/p>\n\n\n\n<p>By Ami<\/p>\n<div class='wp_social_bookmarking_light'>\n            <div class=\"wsbl_google_plus_one\"><g:plusone size=\"medium\" annotation=\"none\" href=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/10642\" ><\/g:plusone><\/div>\n            <div class=\"wsbl_hatena_button\"><a href=\"\/\/b.hatena.ne.jp\/entry\/https:\/\/www.gigas-jp.com\/appnews\/archives\/10642\" class=\"hatena-bookmark-button\" data-hatena-bookmark-title=\"Flutter &#8211; Navigation drawer\" data-hatena-bookmark-layout=\"standard\" title=\"\u3053\u306e\u30a8\u30f3\u30c8\u30ea\u30fc\u3092\u306f\u3066\u306a\u30d6\u30c3\u30af\u30de\u30fc\u30af\u306b\u8ffd\u52a0\"> <img src=\"\/\/b.hatena.ne.jp\/images\/entry-button\/button-only@2x.png\" alt=\"\u3053\u306e\u30a8\u30f3\u30c8\u30ea\u30fc\u3092\u306f\u3066\u306a\u30d6\u30c3\u30af\u30de\u30fc\u30af\u306b\u8ffd\u52a0\" width=\"20\" height=\"20\" style=\"border: none;\" \/><\/a><script type=\"text\/javascript\" src=\"\/\/b.hatena.ne.jp\/js\/bookmark_button.js\" charset=\"utf-8\" async=\"async\"><\/script><\/div>\n            <div class=\"wsbl_twitter\"><a href=\"https:\/\/twitter.com\/share\" class=\"twitter-share-button\" data-url=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/10642\" data-text=\"Flutter &#8211; Navigation drawer\" data-via=\"GIGASJAPAN_APPS\" data-lang=\"ja\">Tweet<\/a><\/div>\n            <div class=\"wsbl_facebook_like\"><div id=\"fb-root\"><\/div><fb:like href=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/10642\" layout=\"button_count\" action=\"like\" width=\"100\" share=\"false\" show_faces=\"false\" ><\/fb:like><\/div>\n            <div class=\"wsbl_facebook_send\"><div id=\"fb-root\"><\/div><fb:send href=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/10642\" colorscheme=\"light\" ><\/fb:send><\/div>\n    <\/div>\n<br class='wp_social_bookmarking_light_clear' \/>\n","protected":false},"excerpt":{"rendered":"<p>Output: This week I would like to share about navigation drawer from Drawer widget. We can create navigation d [&hellip;]<\/p>\n","protected":false},"author":19,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[100],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts\/10642"}],"collection":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/users\/19"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/comments?post=10642"}],"version-history":[{"count":4,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts\/10642\/revisions"}],"predecessor-version":[{"id":10650,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts\/10642\/revisions\/10650"}],"wp:attachment":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/media?parent=10642"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/categories?post=10642"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/tags?post=10642"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}