首页 > 解决方案 > 当我有机会定向性时,颤动抽屉汉堡图标不显示

问题描述

我正在尝试使我的应用程序 RTL,并且我希望抽屉位于右侧。我设法从正确的方向打开它,但汉堡菜单图标消失了。

这是制作布局的代码rtl

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

这是我的抽屉:

              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')
               ],
              ),

          ),

我错过了什么?

标签: flutterflutter-layoutdrawer

解决方案


Directionality使用 using包裹您的家庭子小部件TextDirection.rtl

在此处输入图像描述

    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: (){

                },
                ),

            ]
            )
        ),
        );
    }
    }

推荐阅读