【发布时间】:2019-04-25 04:13:55
【问题描述】:
当我按照Add a Drawer to a screen docs 创建抽屉布局时,它工作正常。但是,我有一个问题,这是菜单图标。
在 Android 中,我使用 DrawerToggle 设置抽屉布局,当我打开抽屉时,菜单图标将变为箭头图标,当我关闭抽屉时,箭头图标将变为菜单图标。
在 Flutter 中,它不能像上面那样工作。
如果你理解我的问题,请帮助我。我搜索了很多,但没有找到解决方案。所以想问问大家。非常感谢。
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
final appTitle = 'Drawer Demo';
@override
Widget build(BuildContext context) {
return MaterialApp(
title: appTitle,
home: MyHomePage(title: appTitle),
);
}
}
class MyHomePage extends StatelessWidget {
final String title;
MyHomePage({Key key, this.title}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text(title)),
body: Center(child: Text('My Page!')),
drawer: Drawer(
// Add a ListView to the drawer. This ensures the user can scroll
// through the options in the Drawer if there isn't enough vertical
// space to fit everything.
child: ListView(
// Important: Remove any padding from the ListView.
padding: EdgeInsets.zero,
children: <Widget>[
DrawerHeader(
child: Text('Drawer Header'),
decoration: BoxDecoration(
color: Colors.blue,
),
),
ListTile(
title: Text('Item 1'),
onTap: () {
// Update the state of the app
// ...
// Then close the drawer
Navigator.pop(context);
},
),
ListTile(
title: Text('Item 2'),
onTap: () {
// Update the state of the app
// ...
// Then close the drawer
Navigator.pop(context);
},
),
],
),
),
);
}
}
【问题讨论】:
-
为什么要更改抽屉图标,因为当抽屉打开时它会隐藏它。 flutter.dev/images/cookbook/drawer.png
-
在大多数情况下,你说的是真的。但有时,抽屉布局在菜单图标和工具栏下方,例如:i.stack.imgur.com/hK4mD.png
-
如果是这种情况,请检查我的答案
标签: flutter