【问题标题】:the argument for the named parameter 'child' was already specified已指定命名参数“child”的参数
【发布时间】:2020-07-23 13:21:32
【问题描述】:

浮动按钮不能同时放置图标和文字? 标题中的错误。

    return new Scaffold(
        appBar: new AppBar(
          title: new Text('Hello'),
          backgroundColor: Colors.blue,
        ),
        body: new Container(
            padding: new EdgeInsets.all(22.0),
            child: new Column(
              children: <Widget>[
                new Text("it's working, $name"),
                new FlatButton(onPressed:()=> onClick('test'), child: new Icon(Icons.accessibility),child : new Text('data'))
              ],
            )));
  }
}

【问题讨论】:

  • 现在可以锁定了。

标签: android-studio flutter flutter-layout


【解决方案1】:

您的问题在 FlatButton 小部件内部,您使用了两次 child 属性。

你可以把texticon,这样:

FlatButton.icon(
      icon: Icon(Icons.accessibility),
      label: Text('data'),
      onPressed: () {
        //Code to execute when Button is clicked
      },
)

【讨论】:

    【解决方案2】:

    我相信将两个孩子包装在一行或一列中会解决您的问题。 FlatButton 只能将一个小部件作为子参数。

    FlatButton(                    
      onPressed:()=> onClick('test')}, 
      child: Row(
        children: <Widget>[
          new Icon(Icons.accessibility),
          new Text('data'),
        ],
      ),
    ),
    

    【讨论】:

    • 添加一个 Row 小部件来解决这个问题是不必要的。看我的回答。
    • 我同意@encubos,您的解决方案更好。我赞成你的帖子。
    猜你喜欢
    • 2021-06-15
    • 2014-09-05
    • 2021-05-13
    • 1970-01-01
    • 2013-07-28
    • 2021-05-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多