如果您创建支架,则可以选择抽屉。如果您现在创建此抽屉,您将自动获得应用栏前导位置的菜单图标。但我想要一个打开抽屉的其他图标。我尝试自己在领先位置制作一个图标按钮,但即使使用“Scafold.of(context).openDrawer()”,此按钮也无法打开抽屉。
是否有任何选项可以替换抽屉按钮的图标?
最佳答案
在 Scaffold
中使用 Key
并通过调用 myKey.currentState.openDrawer()
显示抽屉,这是一个工作代码:
import "package:flutter/material.dart";
class Test extends StatefulWidget {
@override
_TestState createState() => new _TestState();
}
class _TestState extends State<Test> {
final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();
@override
Widget build(BuildContext context) {
return new Scaffold(
key: _scaffoldKey,
drawer: new Drawer(),
appBar: new AppBar(
leading: new IconButton(
icon: new Icon(Icons.settings),
onPressed: () => _scaffoldKey.currentState.openDrawer(),
),
),
);
}
}
关于flutter - 点击 AppBar 打开抽屉,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47435231/