我正在尝试使我的应用成为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')
],
),
),
我想念什么?
答案 0 :(得分:0)
输出:
完整代码:
import 'package:flutter/material.dart';
void main() {
runApp(
MaterialApp(
home: Directionality(
child: MyPage(),
textDirection: TextDirection.rtl, // setting rtl
),
),
);
}
class MyPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
drawer: Drawer(), // your drawer
);
}
}
答案 1 :(得分:0)
如果您不想更改代码。然后您可以按照以下步骤进行操作
leading: IconButton(icon: Icon(Icons.arrow_back), onPressed: (){
Navigator.of(context).pop();
}),
这肯定会为您提供帮助,而无需更改代码并按预期工作。
答案 2 :(得分:0)
使用Directionality
用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: (){
},
),
]
)
),
);
}
}