Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 如何在压力机上编程打开抽屉_Flutter - Fatal编程技术网

Flutter 如何在压力机上编程打开抽屉

Flutter 如何在压力机上编程打开抽屉,flutter,Flutter,我需要在单击浮动按钮时打开应用程序抽屉,但它不会打开。请建议,如果有任何其他事情以外的抽屉,我正在寻找建立过滤部分 这是我的部分代码 final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>(); // drawer: Drawer( // Add a ListView to the drawer. This ensures the user ca

我需要在单击浮动按钮时打开应用程序抽屉,但它不会打开。请建议,如果有任何其他事情以外的抽屉,我正在寻找建立过滤部分

这是我的部分代码

 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),
final GlobalKey\u scaffoldKey=
新的GlobalKey();//
抽屉(
//向抽屉添加列表视图。这确保用户可以滚动
//如果没有足够的垂直线,请通过抽屉中的选项
//空间适合所有东西。
子:ListView(
//重要提示:从ListView中删除任何填充。
填充:EdgeInsets.zero,
儿童:[
抽屉阅读器(
子项:文本(“抽屉标题”),
装饰:盒子装饰(
颜色:颜色,蓝色,
),
),
列表砖(
标题:文本(“项目1”),
onTap:(){
//更新应用程序的状态
// ...
//然后关上抽屉
Navigator.pop(上下文);
},
),
列表砖(
标题:文本(“项目2”),
onTap:(){
//更新应用程序的状态
// ...
//然后关上抽屉
Navigator.pop(上下文);
},
),
],
),
),
floatingActionButton:floatingActionButton.extended(
已按下:(){
//在这里添加你的密码!
_scaffoldKey.currentState.openDrawer();
},
标签:文本(
“过滤器”,
风格:
TextStyle(装饰:textEdition.none,颜色:Colors.black),
),
图标:图标(Icons.filter\u alt,颜色:Colors.black),
背景颜色:颜色。白色),
我犯了一个错误

引发了另一个异常:NoSuchMethodError:对null调用了方法“openDrawer”


你应该把你的脚手架钥匙递给你的脚手架

Scaffold(key: _scaffoldKey);
Scaffold(key:_scaffoldKey)

实际上,您必须在scaffold中设置key属性

Scaffold(key: _scaffoldKey);
Scaffold(key:_scaffoldKey)

然后使用与您使用的相同方法。

抽屉(钥匙:\u scaffoldKey)
脚手架(键:_scaffoldKey,…)
未测试,但如果您这样说,则必须为真。谢谢^^你说得对,我查过了。