flutter - 使用 Scaffold.of(context) 尝试使用 openDrawer() 时,位置参数过多错误,发现 2 而不是 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()),)
));
}
}`
错误:位置参数太多:预期为 0,但找到了 2 个。尝试删除额外的位置参数,或指定命名参数的名称。
请帮我解决这个问题。提前致谢!
解决方案
这是因为你不能像这样传递AppBar
和Drawer
参数Scaffold
..
Scaffold(
AppBar(),
Drawer(),
)
..因为这些是命名参数。相反,您需要将它们与相应的参数名称一起传递,例如..
Scaffold(
appBar: AppBar(),
drawer: Drawer(),
)
推荐阅读
- r - 用 NA 重塑长而完整
- c++ - 关于 std::lower_bound 和 std::upper_bound 的问题
- c# - 带有 if 条件的复选框项目
- android - 在 Google Play 中部分部署应用程序
- android - (R.layout.activity_main)?R 为红色
- regex - 选择 2 个单词之间的一组数字
- javascript - 如何在节点 js 中使用从数据库中选择的异步和等待
- latex - tabularx \linewidth 改装不起作用
- java - 如何从登录按钮前进到下一个代理信息表?
- bash - 我不知道如何从 Haxe 调用 bash 命令