[英]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..这是因为您不能像这样将
AppBar
和Drawer
参数传递给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.