简体   繁体   English

尝试使用 Scaffold.of(context) 使用 openDrawer() 找到 2 而不是 0 时出现太多位置 arguments 错误

[英]Too many positional arguments error when trying to use openDrawer() using Scaffold.of(context) finding 2 instead of 0

class MyApp extends StatelessWidget {
  @override

  Widget build(BuildContext context) {

   return MaterialApp(

        home: SafeArea(

            child: Scaffold(

      Builder(

          builder: (context) => AppBar(

                leading: IconButton(

                  icon: Icon(Icons.accessible),

                  onPressed: () => Scaffold.of(context).openDrawer(),

                ),
                title: Text('Sorted.'),
                backgroundColor: Color(0xff0A3D62),
              )),

      Drawer(

          child: ListView(padding: EdgeInsets.zero, children: <Widget>[

        new UserAccountsDrawerHeader(

          accountName: new Text('XYZ'),
          accountEmail: new Text('XYZ@gmail.com'),
          currentAccountPicture: new CircleAvatar(),
        )
      ])),

      body: Center(child: Home()),)

    ));
  }
}` 

Error: Too many positional arguments: 0 expected, but 2 found.错误:位置 arguments 太多:预期为 0,但找到了 2。 Try removing the extra positional arguments, or specifying the name for named arguments.尝试删除额外的位置 arguments,或指定名为 arguments 的名称。

Please help me resolve this.请帮我解决这个问题。 Thanks in advance!提前致谢!

This is because you cannot pass AppBar and Drawer parameters to Scaffold like this..这是因为您不能像这样将AppBarDrawer参数传递给Scaffold ..

Scaffold(
    AppBar(),
    Drawer(),
)

..because these are named parameters. ..因为这些是命名参数。 Instead, you need to pass them with the corresponding parameter names like..相反,您需要将它们与相应的参数名称一起传递,例如..

Scaffold(
    appBar: AppBar(),
    drawer: Drawer(),
)
return MaterialApp(
    home: SafeArea(
        child: Scaffold(
  appBar: AppBar(
    leading: IconButton(
      icon: Icon(Icons.accessible),
      onPressed: () => Scaffold.of(context).openDrawer(),
    ),
    title: Text('Sorted.'),
    backgroundColor: Color(0xff0A3D62),
  ),
  drawer: Drawer(
      child: ListView(padding: EdgeInsets.zero, children: <Widget>[
    new UserAccountsDrawerHeader(
      accountName: new Text('XYZ'),
      accountEmail: new Text('XYZ@gmail.com'),
      currentAccountPicture: new CircleAvatar(),
    )
  ])),
  body: Center(child: Home()),
)));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Flutter Scaffold.of(context).openDrawer() 不起作用 - Flutter Scaffold.of(context).openDrawer() doesn't work Flutter :此错误出现在使用不包含 Scaffold 的上下文调用的 Scaffold.of() 。 当我尝试展示小吃店时 - Flutter : this error appear Scaffold.of() called with a context that does not contain a Scaffold. when i try to show a snackbar 当我使用 admob flutter 时,位置 arguments 太多 - Too many positional arguments when i use admob flutter 错误:没有名为“nullOk”的命名参数 Scaffold.of(context, nullOk: true) - Error: No named parameter with the name 'nullOk' Scaffold.of(context, nullOk: true) 使用不包含脚手架的上下文调用的 Scaffold.of() - Scaffold.of() called with a context that does not contain a Scaffold 错误:位置参数过多:预期为0,但发现3 - error: Too many positional arguments: 0 expected, but 3 found 错误:位置 arguments 太多:预期为 0,但找到了 9 - error: Too many positional arguments: 0 expected, but 9 found 错误颤动 NotificationDetails 太多位置参数 - Error flutter NotificationDetails too many positional arguments 太多位置 arguments flutter 堆栈错误 - Too many positional arguments flutter stack error 错误:太多位置 arguments:允许 0,但找到 2 - Error: Too many positional arguments: 0 allowed, but 2 found
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM