drawer profile in flutter code example

Example 1: flutter drawer

Scaffold(
   drawer: Drawer(
      child: ListView(
        padding: EdgeInsets.zero,
        children: [
              DrawerHeader(
                   child: Text("Header")),
              ListTile(
                  title: Text("Home"))
        ]),
  ), 
);

Example 2: app drawer in flutter

class navigationDrawer extends StatelessWidget {
 @override
 Widget build(BuildContext context) {
   return Drawer(
     child: ListView(
       padding: EdgeInsets.zero,
       children: <Widget>[
         createDrawerHeader(),
         createDrawerBodyItem(
           icon: Icons.home,text: 'Home'),
         createDrawerBodyItem(
           icon: Icons.account_circle,text: 'Profile'),

         createDrawerBodyItem(
           icon: Icons.event_note,text: 'Events'),
         Divider(),
         createDrawerBodyItem(
           icon: Icons.notifications_active,text: 'Notifications'),
         createDrawerBodyItem(
           icon: Icons.contact_phone,text: 'Contact Info'),
         ListTile(
           title: Text('App version 1.0.0'),
           onTap: () {},
         ),
       ],
     ),
   );
 }
}

Example 3: flutter screen hidden drawer dont show on all pages

class MyDrawer extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Drawer(...);
  }
}
---------------------------------------------------------
And then when using it in each page:

Scaffold(
  drawer: MyDrawer(...),
  ...
)

Example 4: make drawer with profile image flutter

import 'package:flutter/material.dart';

class AppDrawer extends StatefulWidget {
  @override
  _AppDrawerState createState() => new _AppDrawerState();
}

class _AppDrawerState extends State<AppDrawer> {
  @override
  Widget build(BuildContext context) {
    return new Drawer(
      child: Center(
        child: Column(
          children: <Widget>[
            new UserAccountsDrawerHeader(
              decoration: BoxDecoration(color: Colors.white),
              currentAccountPicture: new CircleAvatar(
                radius: 50.0,
                backgroundColor: const Color(0xFF778899),
                backgroundImage:
                    NetworkImage("http://tineye.com/images/widgets/mona.jpg"),
              ),
            ),
          ],
        ),
      ),
    );
  }
}

Example 5: app drawer in flutter

Widget createDrawerHeader() {
 return DrawerHeader(
     margin: EdgeInsets.zero,
     padding: EdgeInsets.zero,
     decoration: BoxDecoration(
         image: DecorationImage(
             fit: BoxFit.fill,
             image:  AssetImage('images/bg_header.jpeg'))),
     child: Stack(children: <Widget>[
       Positioned(
           bottom: 12.0,
           left: 16.0,
           child: Text("Welcome to Flutter",
               style: TextStyle(
                   color: Colors.white,
                   fontSize: 20.0,
                   fontWeight: FontWeight.w500))),
     ]));
}

Tags:

Misc Example