【发布时间】:2021-04-10 00:52:15
【问题描述】:
我需要在单击浮动按钮时打开应用程序抽屉,但它没有打开。请建议是否有除抽屉以外的任何其他东西我正在寻找构建过滤器部分
这是我的部分代码
final GlobalKey<ScaffoldState> _scaffoldKey =
new GlobalKey<ScaffoldState>(); //
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);
},
),
],
),
),
floatingActionButton: FloatingActionButton.extended(
onPressed: () {
// Add your onPressed code here!
_scaffoldKey.currentState.openDrawer();
},
label: Text(
'Filter',
style:
TextStyle(decoration: TextDecoration.none, color: Colors.black),
),
icon: Icon(Icons.filter_alt, color: Colors.black),
backgroundColor: Colors.white),
我遇到错误
引发了另一个异常:NoSuchMethodError: 方法 'openDrawer' 在 null 上被调用。
【问题讨论】:
标签: flutter