flutter - 单击左上角按钮单击(汉堡图标)时如何从侧面打开屏幕?
问题描述
单击图标时,我希望从左侧打开侧面菜单。
代码:
class _MovieScreenState extends State<MovieScreen> {
MovieBloc _bloc;
final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();
@override
void initState() {
super.initState();
_bloc = MovieBloc();
}
@override
Widget build(BuildContext context) {
return Scaffold(
key: _scaffoldKey,
drawer: new Drawer(),
appBar: AppBar(
backgroundColor: Color(0xffFAFCF7), // status bar color
brightness: Brightness.light,
elevation: 0.0,
leading: Container(
margin: EdgeInsets.only(left: 17),
child: RawMaterialButton(
onPressed: _scaffoldKey.currentState.openDrawer(),
child: new Icon(
Icons.menu,
// color: Colors.black,
size: 25.0,
),
shape: new CircleBorder(),
elevation: 4.0,
fillColor: Colors.white,
padding: const EdgeInsets.all(5.0),
),
...
所以,onTap 我希望用全屏覆盖从左侧打开屏幕。另外,如果在主屏幕上从左向右滑动,是否可以打开侧屏幕。谢谢
解决方案
是的,这是可能的,您正在寻找的小部件是Drawer
将参数传递drawer
到您的 Scaffold 中,您将看到汉堡包图标
class LeftMenu extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(child:
ListView(
padding: EdgeInsets.zero,
children: // your widgets that you want to put inside
)
)
}
}
Scaffold(
drawer: Drawer(
child: LeftMenu()
)
);
现在可以使用汉堡菜单或从右向左滑动打开它。
您可以在官方教程中阅读更多信息:抽屉
推荐阅读
- qt - 如何在设置变量中存储字符串列表?
- java - 套接字崩溃线程
- flutter - 将内容添加到自定义 Widget 类 Flutter
- python - 使用 SQLAlchemy 取值的对数 - Flask/SQLAlchemy
- notepad++ - 在记事本++中的同一行上重复单词
- oracle - 需要帮助来确定通过 dblink 访问视图所需的权限
- javascript - 如何从字符串变量定义对象字段名称><
- python - 在 Telepot 上弄脏我的手并面临问题
- hive - hive表有多个分区字段时如何只更新一个分区字段?
- python-3.x - subprocess.run gnu 并行调用