drawer_master_detail

A new Flutter package to build a Drawer like Master Detail Page of Xamarin and Android Native Drawer.

Getting Started

Usage Example

import drawer_master_detail.dart

import 'package:drawer_master_detail/drawer_master_detail.dart';

Samples

import 'package:drawer_master_detail/drawer_master_detail.dart';
import 'package:drawer_master_detail/model/drawer_master_item.dart';
import 'package:example_drawer_master_detail/src/pages/page_01.dart';
import 'package:example_drawer_master_detail/src/pages/page_02.dart';
import 'package:example_drawer_master_detail/src/pages/page_03.dart';
import 'package:flutter/material.dart';

class HomePage extends StatefulWidget {
  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  @override
  Widget build(BuildContext context) {
    return DrawerMasterDetail(      
      selectedBackGroundColor: Colors.grey,
      drawerMasterItems: [
        DrawerMasterItem(page: Page01(),item:ListTile(title: Text("Page 01"),), selectedItem:ListTile(title: Text("Page 01" , style: TextStyle(color: Colors.white), ),) ),
        DrawerMasterItem(page: Page02(),item:ListTile(title: Text("Page 02"),)),
        DrawerMasterItem(page: Page03(),item:ListTile(title: Text("Page 03"),)),
        DrawerMasterItem.customItem(Divider(
          color: Colors.red,
        )),
        DrawerMasterItem(page: Page03(),item:ListTile(title: Text("Page 04"),) , appBar:AppBar(title: Text("Menu legal"),),),
        DrawerMasterItem(page: Page03(),item:ListTile(title: Text("Page 05"),)),
        DrawerMasterItem(page: Page03(),item:ListTile(title: Text("Page 06"),)),
        DrawerMasterItem(page: Page03(),item:ListTile(title: Text("Page 07"),)),        
        DrawerMasterItem(page: Page03(),item:ListTile(title: Text("Page 08"),)),
        DrawerMasterItem.customItem(Container(         
          child: Column(            
            children: <Widget>[            
              Divider(),
              Text("Titulo Diferente", style: TextStyle(color: Colors.grey),),            
            ],
          ),
        )),
        DrawerMasterItem(page: Page03(),item:ListTile(title: Text("Page 09"),)),
        DrawerMasterItem(page: Page03(),item:ListTile(title: Text("Page 10"),)),
        DrawerMasterItem(page: Page03(),item:ListTile(title: Text("Page 11"),)),
        DrawerMasterItem(page: Page03(),item:ListTile(title: Text("Page 12"),)),
        DrawerMasterItem(page: Page03(),item:ListTile(title: Text("Page 13"),)),
        DrawerMasterItem(page: Page03(),item:ListTile(title: Text("Page 14"),)),
      ],
      footer: Container(
        height: 50,
        alignment: Alignment.center,
        width: double.infinity,
        color: Colors.red,
        child: Text("Footer")),
   //   header: Text("Casa"),
      userAccountsDrawerHeader: UserAccountsDrawerHeader(
        accountEmail: Text("bwolfnoob@gmail.com"),
        accountName: Text("bwolf"),
        currentAccountPicture: CircleAvatar(
          child: Text("BW"),
          backgroundColor: Colors.yellowAccent,
        ),
      ),
      
      initPage: DrawerMasterItem(page: Page01(),item:ListTile(title: Text("Home Page"),) ),
    );
  }
}

Samples dynamicaly


class HomeDynamicPage extends StatefulWidget {
  @override
  _HomeDynamicPageState createState() => _HomeDynamicPageState();
}

class _HomeDynamicPageState extends State<HomeDynamicPage> {
  var bloc = HomeDynamicModule.to.getBloc<HomeDynamicBloc>();

  @override
  Widget build(BuildContext context) {
    return DrawerMasterDetail(
      selectedBackGroundColor: Colors.grey,
      builder: () {

        // if (logged) {
        //    return
        //     [ DrawerMasterItem(
        //        page: Page01(),
        //        item: ListTile(
        //          title: Text("Page 01"),
        //        ),
        //        selectedItem: ListTile(
        //          title: Text(
        //            "Page 01",
        //            style: TextStyle(color: Colors.white),
        //          ),
        //        ),
        //      ),
        //      DrawerMasterItem(
        //        page: Page02(),
        //        item: ListTile(
        //          title: Text("Page 02"),
        //        ),
        //      ),
        //      DrawerMasterItem(
        //        page: Page03(),
        //        item: ListTile(
        //          title: Text("Page 03"),
        //        ),
        //      ),
        //     ];       
        //   } else {
        //     return [];
        // },
      
       
        return [
          DrawerMasterItem(
            page: Page01(),
            item: ListTile(
              title: Text("Page 01"),
            ),
            selectedItem: ListTile(
              title: Text(
                "Page 01",
                style: TextStyle(color: Colors.white),
              ),
            ),
          ),
          DrawerMasterItem(
            page: Page02(),
            item: ListTile(
              title: Text("Page 02"),
            ),
          ),
          DrawerMasterItem(
            page: Page03(),
            item: ListTile(
              title: Text("Page 03"),
            ),
          ),         
         //     ....
        ];
      },
      footer: Container(
          height: 50,
          alignment: Alignment.center,
          width: double.infinity,
          color: Colors.red,
          child: Text("Footer")),
      headerMenuBuilder: () {

       // if (logged) {
       //       return UserAccountsDrawerHeader(
       //         accountEmail: Row(
       //           children: <Widget>[
       //             Text("bwolfnoob@gmail.com"),
       //             Spacer(),
       //             FlatButton(
       //               onPressed: () {
       //                 bloc.logOut();
       //               },
       //               child: Text(
       //                 "LogOut",
       //                 style: TextStyle(color: Colors.white),
       //               ),
       //             )
       //           ],
       //         ),
       //         accountName: Text("bwolf"),
       //         currentAccountPicture: CircleAvatar(
       //           child: Text("BW"),
       //           backgroundColor: Colors.yellowAccent,
       //         ),
       //       );
       //     } else {
       //       return Container(
       //         height: 200,
       //         child: Column(
       //           mainAxisAlignment: MainAxisAlignment.center,
       //           crossAxisAlignment: CrossAxisAlignment.center,
       //           children: <Widget>[
       //             Text("You aren't logged"),
       //             RaisedButton(
       //               onPressed: () {
       //                 bloc.logIn();
       //               },
       //               child: Text("Login"),
       //             )
       //           ],
       //         ),
       //       );
       //     }
       //   },
       // );

        return StreamBuilder<bool>(
          stream: bloc.logged,
          builder: (BuildContext context, AsyncSnapshot snapshot) {
          
            if (!snapshot.hasData) {
              return CircularProgressIndicator();
            }

            if (snapshot.data) {
              return UserAccountsDrawerHeader(
                accountEmail: Row(
                  children: <Widget>[
                    Text("bwolfnoob@gmail.com"),
                    Spacer(),
                    FlatButton(
                      onPressed: () {
                        bloc.logOut();
                      },
                      child: Text(
                        "LogOut",
                        style: TextStyle(color: Colors.white),
                      ),
                    )
                  ],
                ),
                accountName: Text("bwolf"),
                currentAccountPicture: CircleAvatar(
                  child: Text("BW"),
                  backgroundColor: Colors.yellowAccent,
                ),
              );
            } else {
              return Container(
                height: 200,
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: <Widget>[
                    Text("You aren't logged"),
                    RaisedButton(
                      onPressed: () {
                        bloc.logIn();
                      },
                      child: Text("Login"),
                    )
                  ],
                ),
              );
            }
          },
        );
      },
      initPage: DrawerMasterItem(
          page: Page01(),
          item: ListTile(
            title: Text("Home Page"),
          )),
    );
  }
}

Libraries

drawer_bloc
drawer_master
drawer_master_detail
drawer_master_item