Drawer in flutter

 Drawer 


In apps that use Material Design, there are two primary options for navigation: tabs and drawers. When there is insufficient space to support tabs, drawers provide a handy alternative.

In Flutter, use the Drawer widget in combination with a Scaffold to create a layout with a Material Design drawer.

You can create a drawer as following steps:

  • Create a scaffold
  • In scaffold you have a drawer 
  • Create a Drawer widget 
  • It takes a child and you can provide ListView widget
  • In ListView widget you have a DrawerHeader widget which provide a header for drawer
  • And you can add other widget in listview such as ListTile, Container, etc.

Output:





Full code:



import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text("Drawer"),
          
        ),
        drawer: Drawer(child: ListView(
          padding: EdgeInsets.zero,
          children: [
              DrawerHeader(
                decoration: BoxDecoration(color: Colors.blue),

              child: Text("Drawer Header",
              style: TextStyle(color: Colors.white,
              ),
              ),
              )
          
          ,ListTile(
            onTap: (){},
            leading: Text("Item 1"),
          )
            
          ,ListTile(
            onTap: (){},
            leading: Text("Item 2"),
          )  
          ,ListTile(
            onTap: (){},
            leading: Text("Item 3"),
          )  
          ,ListTile(
            onTap: (){},
            leading: Text("Item 4"),
          )
          
          ],
        ),) ,
      ),
      
    );
  }
}


Comments

Popular Posts