ProAndroidDev

The latest posts from Android Professionals and Google Developer Experts.

Follow publication

Flutter: Creating Drawers

Member-only story

Flutter: Creating Drawers

Daksh Gupta
ProAndroidDev
Published in
7 min readJun 12, 2018

Flutter is a mobile App SDK by Google which helps in creating modern mobile apps for iOS and Android using a single(almost) code base. It’s a new entrant in the cross platform mobile application development and unlike other frameworks like React Native, it doesn’t use JavaScript but DART as a Programming Language.

It’s highly recommended to read my first post “Flutter: From Zero To Comfortable” to get a good sense of how Flutter widgets work and what’s going on here in this post.

What is a Drawer?

A drawer is an invisible side screen which generally contain menu items and occupies around half of the screen when displayed. If you’ve ever used apps like Twitter and/or GMail, you already know what I’m talking about.

Creating Empty Drawer

Let’s first create an empty drawer. As with other flutter applications with material design, we’ll be creating a basicMaterialApp , the home of which shall contain a Scaffold with Drawer

Here is how the code for basic MaterialApp shall look like

class MyApp extends StatelessWidget {
@override
Widget build (BuildContext ctxt) {
return new MaterialApp(
home: new DWidget()
);
}
}

The DWidget here is the widget which will contain drawers. It should be noted that drawers are part of Scaffold along with appBar and body . Once we add drawer to the Scaffold, it generates a three line menu item on the top left corner of the application bar, which on clicking displays the drawer screen.

Here is how the basic code shall look like.

class DWidget extends StatelessWidget {
@override
Widget build (BuildContext ctxt) {
return new Scaffold(
drawer: new Drawer(
child: new Text("\n\n\nDrawer Is Here"),
),
appBar: new AppBar(
title: new Text("Drawer Demo"),
),
body: new Text("Drawer Body"),
);
}
}

This will create an app with a bare minimum drawer as displayed below.

As you might have noticed that drawer, takes child: and not children: , which means at any point of time we can have only one widget inside drawer.

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Published in ProAndroidDev

The latest posts from Android Professionals and Google Developer Experts.

Written by Daksh Gupta

🔹Software Product Development Catalyst 🔹 Tech Speaker & Content Creator 🔹 Bio @ https://CodeSportsAi.Tech

Responses (15)

Hi Daksh, your tutorials are very easy to follow and catch up. You are really a great teacher. Is your tutorials on online learning websites like Udemy?

--

Daksh, you do really great tutorials !! Please keep continue to add new Flutter topics, you’re really good at explaining, i’m learning so much with them !!

--