Column(
mainAxisSize: MainAxisSize.min,
children: [
Container(
color: Colors.black,
width: double.infinity,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: awards
.map((award) => Card(
elevation: 3,
surfaceTintColor: Colors.white,
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 8, vertical: 16.0),
child: Column(
mainAxisSize: MainAxisSize.min,
// crossAxisAlignment: CrossAxisAlignment.stretch, <--- Why this guy is breaking ? logic ?
children: [
SizedBox(
// width: double.maxFinite, <--- So does this guy :(
child: OutlinedButton(
onPressed: () {}, child: const Text("Hello")),
)
],
),
),
))
.toList(),
),
),
],
));
I am trying to spread the button width across card inside row, but nothing is working.
I don't even understand why it is breaking, it is saying it is breaking in the boxconstraints as it has infinite width
我正试着将按钮宽度扩展到卡内的行间,但都不起作用。我甚至不明白它为什么要断开,它说它在框约束中断开,因为它有无限的宽度
更多回答
I want the column, dont ask me to remove the column, I have removed for the sake of simplicity
我想要这个专栏,不要让我删除这个专栏,我删除是为了简单起见
Can you add your expected/wanted design?
你能添加你期望的/想要的设计吗?
优秀答案推荐
You can use the LayoutBuilder to get the max width that can use for every card
您可以使用LayoutBuilder获取可用于每张卡的最大宽度
Here you go. I believe this is what you want. It is the minimum viable code, under 50 lines. I hope it works. Feel free to provide acknowledgement in the comment below.
这就是你要的。我相信这就是你想要的。这是最小的可行代码,不超过50行。我希望它能起作用。请随时在下面的评论中提供确认。
Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Container(
color: Colors.black,
width: double.infinity,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <String>[
"A 1",
"A 2",
"A 3",
"A 4",
"A 5",
].map(
(String award) {
return Expanded(
child: Card(
elevation: 3,
surfaceTintColor: Colors.white,
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 8,
vertical: 16.0,
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
SizedBox(
child: OutlinedButton(
onPressed: () {},
child: Text(award),
),
)
],
),
),
),
);
},
).toList(),
),
),
],
),
更多回答
我是一名优秀的程序员,十分优秀!