flutter drawer Hamburger icon is not showing when i chance Directionality

6,121

Wrap your home child widget with Directionality using TextDirection.rtl

enter image description here

    import 'package:flutter/material.dart';

    class DrawerLayoutApp extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
        return new MaterialApp(
            title: "My Apps",
            theme: new ThemeData(
                fontFamily: "Vazir",
                primaryColor: Color(0xff075e54),
                accentColor: Color(0xff25d366),
                primaryIconTheme: new IconThemeData(color: Colors.white)
            ),
            home: new Directionality(textDirection: TextDirection.rtl, child: new DrawerLayoutAppBody())
        );
    }
    }

    class DrawerLayoutAppBody extends StatefulWidget {
    @override
    State<StatefulWidget> createState() => new DrawerLayoutAppBodyState();
    }

    class DrawerLayoutAppBodyState extends State<DrawerLayoutAppBody>{
    TextStyle listTileTextStyle = new TextStyle(
        color: Colors.black,
        fontWeight: FontWeight.bold,
        fontSize: 18
    );

    @override
    Widget build(BuildContext context) {
        return new Scaffold(
        appBar: new AppBar(
            title: new Text("برنامه های من")
        ),
        drawer: new Drawer(
            child: new ListView(
            children: <Widget>[
                new Container(
                    height: 120,
                    child: new DrawerHeader(
                    padding: EdgeInsets.zero,
                    child: new Container(
                        decoration: new BoxDecoration(
                            gradient: new LinearGradient(
                                colors: <Color>[
                                Theme.of(context).primaryColor,
                                const Color(0xff05433c),
                                ],
                                begin: Alignment.topCenter,
                                end:  Alignment.bottomCenter
                            )
                        ),

                    )
                    )
                ),
                new ListTile(
                leading: new Icon(Icons.map, color: Colors.black),
                title: new Text(
                    'گوگل مپ',
                    style: listTileTextStyle
                ),
                onTap: (){

                },
                ),

            ]
            )
        ),
        );
    }
    }
Share:
6,121
Sarah
Author by

Sarah

Updated on December 14, 2022

Comments

  • Sarah
    Sarah over 1 year

    I am trying to make my app RTL and I want the drawer to be on the right side. I managed to open it from the right direction but the hamburger menu icon disappeared.

    This is code to make the layout rtl:

    class MyApp extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return new MaterialApp(
          title: 'Flutter task',
          home: Directionality(
            textDirection: TextDirection.rtl,
              child: new MyHomePage()
          ),
        );
      }
    }`
    

    and this is my drawer :

                  drawer: new Container(
                constraints: new BoxConstraints.expand(
                  width: MediaQuery
                      .of(context)
                      .size
                      .width - 60,
                ),
                color: Colors.black.withOpacity(0.6),
                alignment: Alignment.center,
                  child: new ListView(
                   children: <Widget>[
                     Text('1'),
                     Text('2')
                   ],
                  ),
    
              ),
    

    What am I missing?

    • Aakash Kumar
      Aakash Kumar almost 5 years
      Can you send some code of the scaffold where you are using this drawer?
  • CopsOnRoad
    CopsOnRoad almost 5 years
    Don't pass any child to Drawer and check if it is working.
  • Sarah
    Sarah almost 5 years
    still the same !