我是新的Flutter,我已经创建了一个菜单按钮,以打开一个侧菜单,但然而,我需要一些帮助,使它发生。
任何人都可以帮助我实现或指导我在我的代码如何使它的工作。请和非常感谢!
下面是我的代码:
Widget _icon(IconData icon, {Color color = LightColor.iconColor}) {
return Container(
padding: EdgeInsets.all(10),
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(13)),
color: Theme.of(context).backgroundColor,
boxShadow: AppTheme.shadow),
child: Icon(
icon,
color: color,
),
);
}
主服务器:
class _MainPageState extends State<MainPage> {
bool isHomePageSelected = true;
Widget _appBar() {
return Container(
padding: AppTheme.padding,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
RotatedBox(
quarterTurns: 4,
child: _icon(Icons.menu, color: Colors.black54),
),
ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(13)),
child: Container(
decoration: BoxDecoration(
color: Theme.of(context).backgroundColor,
boxShadow: <BoxShadow>[
BoxShadow(
color: Color(0xfff8f8f8),
blurRadius: 10,
spreadRadius: 10),
],
),
),
)
],
),
);
}
3条答案
按热度按时间avwztpqn1#
你可以复制粘贴运行下面的完整代码
您可以使用
GlobalKey()
并调用_key.currentState.openDrawer();
代码片段
工作演示
全码
whhtz7ly2#
使用此代码:
参考:https://api.flutter.dev/flutter/material/ScaffoldState/openDrawer.html
disbfnqx3#
建议的方法是调用
Scaffold.of(context).openDrawer();
样本代码: