我尝试扩展容器布局。我尝试使用扩展的小部件,但仍然不能正常工作。我想扩展到最大尺寸的蓝色容器,如您在下面的示例中看到的。你有什么建议我怎么做吗?或者我可以使用哪个小部件来解决我的问题?
这是我的代码:

Container(
padding: EdgeInsets.all(3),
child: Column(
    crossAxisAlignment: CrossAxisAlignment.start,
    children: <Widget>[
    Row(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
        CircleAvatar(
            backgroundColor: Colors.brown.shade800,
            child: Text("J")),
        Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
            Text("Some text"),
            Container(
                decoration: new BoxDecoration(
                    border: new Border.all(color: Colors.blueAccent)),
                child: Text("How expand this container to max width?"))
            ],
        )
        ],
    )
    ],
));

flutter - 如何在布局中展开嵌套容器?-LMLPHP
谢谢

最佳答案

column小部件包装Expanded小部件,并将crossAxisAlignment: CrossAxisAlignment.start更改为crossAxisAlignment: CrossAxisAlignment.stretch

Expanded(
  child: Column(
     crossAxisAlignment: CrossAxisAlignment.stretch,
     children: <Widget>[
        Text("Some text"),
        Container(
           decoration: new BoxDecoration(
              border: new Border.all(color: Colors.blueAccent)
           ),
           child: Text("How expand this container to max width?")
       )
    ],
 ),
)

10-08 17:56