flutter - 有没有办法在容器中包含多个子代?

标签 flutter dart flutter-layout

这是完整的代码:

class Application extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new Scaffold(
       body: new Container(
         color: Color(0xff258DED),
         height: 400.0,
         alignment: Alignment.center,
         child: new Container(
           height: 200.0,
           width: 200.0,
           decoration: new BoxDecoration(
             image: DecorationImage(
                 image: new AssetImage('assets/logo.png'),
             fit: BoxFit.fill
             ),
             shape: BoxShape.circle
           ),
         ),
         child: new Container(
          child: new Text('Welcome to Prime Message',
            textAlign: TextAlign.center,
            style: TextStyle(
                fontFamily: 'Aleo',
                fontStyle: FontStyle.normal,
                fontWeight: FontWeight.bold,
                fontSize: 25.0,
                color: Colors.white
            ),
          ),
         ),
        ),
      ),
    );
  }
}

我尝试在顶部添加Container,然后在其中添加两个 child 。第一个 child 工作正常,但是第二个 child 给我错误,例如“已指定命名参数'child'的参数”。

最佳答案

如果您试图在一个容器中放置多个子代,则对于线性子代,您希望将其视为Row()Column()类。如果要让 float 子项彼此重叠,则使用Stack()

例如:

class Application extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
        return new MaterialApp(
            home: new Scaffold(
                body: new Container(
                    color: Color(0xff258DED),
                    height: 400.0,
                    alignment: Alignment.center,
                    child: new Column(
                        children: [
                            new Container(
                                height: 200.0,
                                width: 200.0,
                                decoration: new BoxDecoration(
                                    image: DecorationImage(
                                        image: new AssetImage('assets/logo.png'),
                                        fit: BoxFit.fill
                                    ),
                                    shape: BoxShape.circle
                                ),
                            ),
                            new Container(
                                child: new Text('Welcome to Prime Message',
                                    textAlign: TextAlign.center,
                                    style: TextStyle(
                                        fontFamily: 'Aleo',
                                        fontStyle: FontStyle.normal,
                                        fontWeight: FontWeight.bold,
                                        fontSize: 25.0,
                                        color: Colors.white
                                    ),
                                ),
                            ),
                        ],
                    ),
                ),
            ),
        );
    }
}

关于flutter - 有没有办法在容器中包含多个子代?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57553821/

相关文章:

Flutter:如何处理具有空值的图像?

flutter - Flutter:如何制作自定义的动画下拉菜单?

Flutter Gridview 在列中。有什么解决办法..?

android - 如何在 Flutter 中自动刷新 listView?

flutter - 删除 flutter 中的日期

dart - 在列表列表中每个项目的开头插入列表项目

android - Flutter:禁用选项卡导航直到表单验证完成

flutter - 如何用 flutter 修复页脚中的小部件

flutter - 带有图标和文本位置左侧的按钮

datetime - Flutter:DateTime.now 不反射(reflect)手动设置的时区