74

How to place Drawer widget on the right. Also is possible to place two Drawer widget in a single page one either side of the appbar

Widget build(BuildContext context){
 return Scaffold(
  drawer: Drawer(
    child: ListView(
      children: <Widget>[
        ListTile(
          leading: Icon(Icons.shopping_cart),
          title: Text('Checkout'),
          onTap: (){
            Navigator.pushNamed(context, '/home');
          },
        ),
        ListTile(
          leading: Icon(Icons.report),
          title: Text('Transactions'),
          onTap: (){
            Navigator.pushNamed(context, '/transactionsList');
          },
        ),
      ]
    )
  ),
  body: SingleChildScrollView(
    child: Column(
      children : [
        _buildOrderHeader(),
        _buildOrderDetails(context),
      ]
    )
  )
);

}'

KURRU HEM
  • 1,643
  • 3
  • 15
  • 22

4 Answers4

166

By using endDrawer: ... instead or in addition to drawer: ... to set a drawer, like this:

Scaffold(
  endDrawer: Drawer(...),
  // ...
)

To open it programmatically, use

Scaffold.of(context).openEndDrawer(); //This might have been updated by flutter team since the last edit

See also https://docs.flutter.io/flutter/material/Scaffold/endDrawer.html

Sid
  • 378
  • 1
  • 13
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
  • Thanks for the answer. I need to open the endDrawer when the appbar Action button is taped – KURRU HEM Nov 14 '18 at 13:55
  • 15
    `Scaffold.of(context).openEndDrawer()` https://docs.flutter.io/flutter/material/ScaffoldState/openEndDrawer.html – Günter Zöchbauer Nov 14 '18 at 14:33
  • @GünterZöchbauer Finally, able to get past my hero, [ranking #2](https://stackoverflow.com/tags/flutter/topusers) in Flutter. – CopsOnRoad May 06 '21 at 15:41
  • `drawer` widget in flutter, default opens from left-to-right and the `endDrawer` by default opens from right-to-left. – Si 12 Jul 31 '22 at 11:42
10

To open navigation drawer from right side with Dart Null Safety, You should use endDrawer(). There is two drawer arguments available in flutter.

  1. Drawer (left side)
  2. endDrawer (Right side) you can see the example for endDrawer.

To open endDrawer on Button click.

_scaffoldKey.currentState!.openEndDrawer();

Create Global Key

final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();

inside Build()

Scaffold(
  backgroundColor: backgroundcolor_cust,
  key: _scaffoldKey,
  endDrawer: Drawer(
    elevation: 16.0,
    child: leftDrawerMenu(context, user_phone, cart_count),
  ),
)
Pedro Luz
  • 2,694
  • 4
  • 44
  • 54
Kamal Bunkar
  • 1,354
  • 1
  • 16
  • 20
8
endDrawer: Drawer(
  child: Center(
    child: Column(
      children: const [
        Text('End Drawer'),
      ],
    ),
  ),
),
Pedro Luz
  • 2,694
  • 4
  • 44
  • 54
Osama Sandhu
  • 411
  • 6
  • 11
-1

If you want to keep the button on right and the drawer in the left, then add the hamburger button inside a container, so that hamburger button will be on the right side and the navigation drawer remains in the left side. (not recommended)

new Container(
  alignment: Alignment.topRight,
  margin: EdgeInsets.only(top: 20.0, right: 10.0),
  child: IconButton(
    icon: Icon(
      Icons.menu,
      size: 24,
      color: Colors.white,
    ),
    onPressed: () => scaffoldKey.currentState.openDrawer(),
  ),
)
Christian Giupponi
  • 7,408
  • 11
  • 68
  • 113
user7418129
  • 1,074
  • 14
  • 18