首页 > 解决方案 > 重复的命名参数 - 如何在颤动的身体中添加一个以上的孩子?

问题描述

导入“包:颤振/material.dart”;

第 18 行错误:

错误:已指定命名参数“child”的参数。尝试删除其中一个命名参数,或更正其中一个名称以引用不同的命名参数。dart(duplicate_named_argument)

为什么身体不能多生一个孩子?如何解决?

class mainMenu extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Bar Iland"),

      ),
      body: Center(
        child:
         Image.asset(
                    'assets/Bar_Iland_line.png',
                    height: 200,
                    color: Colors.black.withOpacity(0.80),
                  ),
        child:
          Column( 
          children: <Widget>[
            Spacer(flex: 8),
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceEvenly,
              children:[                  
                    SizedBox.fromSize(
                      size: Size(90, 90), // button width and height
                      child: ClipOval(
                        child: Material(
                          color: Colors.orange, // button color
                          child: InkWell(
                            splashColor: Colors.green, // splash color
                            onTap: () {}, // button pressed
                            child: Column(
                              mainAxisAlignment: MainAxisAlignment.center,
                              children: <Widget>[
                                Icon(Icons.call), // icon
                                Text("Call"), // text
                              ],
                            ),
                          ),
                        ),
                      ),
                    ),

                    SizedBox.fromSize(
                      size: Size(90, 90), // button width and height
                      child: ClipOval(
                        child: Material(
                          color: Colors.orange, // button color
                          child: InkWell(
                            splashColor: Colors.green, // splash color
                            onTap: () {}, // button pressed
                            child: Column(
                              mainAxisAlignment: MainAxisAlignment.center,
                              children: <Widget>[
                                Icon(Icons.call), // icon
                                Text("Call"), // text
                              ],
                            ),
                          ),
                        ),
                      ),
                    ),

                    SizedBox.fromSize(
                      size: Size(90, 90), // button width and height
                      child: ClipOval(
                        child: Material(
                          color: Colors.orange, // button color
                          child: InkWell(
                            splashColor: Colors.green, // splash color
                            onTap: () {}, // button pressed
                            child: Column(
                              mainAxisAlignment: MainAxisAlignment.center,
                              children: <Widget>[
                                Icon(Icons.call), // icon
                                Text("Call"), // text
                              ],
                            ),
                          ),
                        ),
                      ),
                    ),

              ],
            ),
            Spacer(flex: 1),
            Row(
              crossAxisAlignment: CrossAxisAlignment.center,
              mainAxisAlignment: MainAxisAlignment.spaceEvenly,
              children:[
                    SizedBox.fromSize(
                      size: Size(90, 90), // button width and height
                      child: ClipOval(
                        child: Material(
                          color: Colors.orange, // button color
                          child: InkWell(
                            splashColor: Colors.green, // splash color
                            onTap: () {}, // button pressed
                            child: Column(
                              mainAxisAlignment: MainAxisAlignment.center,
                              children: <Widget>[
                                Icon(Icons.call), // icon
                                Text("Call"), // text
                              ],
                            ),
                          ),
                        ),
                      ),
                    ),
                    SizedBox.fromSize(
                      size: Size(90, 90), // button width and height
                      child: ClipOval(
                        child: Material(
                          color: Colors.orange, // button color
                          child: InkWell(
                            splashColor: Colors.green, // splash color
                            onTap: () {}, // button pressed
                            child: Column(
                              mainAxisAlignment: MainAxisAlignment.center,
                              children: <Widget>[
                                Icon(Icons.call), // icon
                                Text("Call"), // text
                              ],
                            ),
                          ),
                        ),
                      ),
                    ),
                    SizedBox.fromSize(
                      size: Size(90, 90), // button width and height
                      child: ClipOval(
                        child: Material(
                          color: Colors.orange, // button color
                          child: InkWell(
                            splashColor: Colors.green, // splash color
                            onTap: () {}, // button pressed
                            child: Column(
                              mainAxisAlignment: MainAxisAlignment.center,
                              children: <Widget>[
                                Icon(Icons.call), // icon
                                Text("Call"), // text
                              ],
                            ),
                          ),
                        ),
                      ),
                    ),
              ],
            ),
            Spacer(flex: 10),
          ],
          ),
        ),
    );
  }
}

标签: flutterdart

解决方案


正如 pskink 提到的,你不能在一个身体里有两个孩子。

利用

Scaffold(
  body: Column( // or Row or Wrap 
     children: [
       Child1(),
       Child2(),
     ]
  )
)

推荐阅读