簡體   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()),)

    ));
  }
}` 

錯誤:位置 arguments 太多:預期為 0,但找到了 2。 嘗試刪除額外的位置 arguments,或指定名為 arguments 的名稱。

請幫我解決這個問題。 提前致謝!

這是因為您不能像這樣將AppBarDrawer參數傳遞給Scaffold ..

Scaffold(
    AppBar(),
    Drawer(),
)

..因為這些是命名參數。 相反,您需要將它們與相應的參數名稱一起傳遞,例如..

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM