gpt4 book ai didi

flutter - 如何在布局中扩展嵌套容器?

转载 作者:IT王子 更新时间:2023-10-29 06:48:36 24 4
gpt4 key购买 nike

我正在尝试扩展容器布局。我尝试使用 Expanded 小部件,但仍然无法正常工作。我想扩展到最大尺寸的蓝色容器,您可以在下面的示例中看到。你有什么建议吗?或者我可以使用什么小部件来解决我的问题?

这是我的代码:

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?"))
],
)
],
)
],
));

widget screenshot

谢谢

最佳答案

我无法解释这一点,但它只适用于两个 Expanded:

ConstrainedBox(
constraints: BoxConstraints(maxWidth: MediaQuery.of(context).size.width),
child: Container(
padding: EdgeInsets.all(3),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
CircleAvatar(
backgroundColor: Colors.brown.shade800, child: Text("J")),
Expanded(
child: Column(
key: key,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text("Some text"),
Container(
decoration: new BoxDecoration(
border: new Border.all(color: Colors.blueAccent)),
child: Row(
children: <Widget>[
Expanded(
child: Text(
"How expand this container to max width?"))
],
),
),
],
),
)
],
)
],
),
),
);

关于flutter - 如何在布局中扩展嵌套容器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57287623/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com