gpt4 book ai didi

如果在另一个列内的列中使用间隔器,则会出现 flutter 无界高度错误

转载 作者:行者123 更新时间:2023-12-03 08:13:23 29 4
gpt4 key购买 nike

我被困住了......这是我的代码分解:

 Column(
children: [
Column(
children: [
Text('Whyy'),
Spacer(),
Text('crash?'),
],
),
Text('ok'),
],
),

这会因错误而崩溃:

RenderFlex children have non-zero flex but incoming height constraints are unbounded.

When a column is in a parent that does not provide a finite heightconstraint, for example if it is in a vertical scrollable, it will tryto shrink-wrap its children along the vertical axis. Setting a flex ona child (e.g. using Expanded) indicates that the child is to expand tofill the remaining space in the vertical direction. These twodirectives are mutually exclusive. If a parent is to shrink-wrap itschild, the child cannot simultaneously expand to fit its parent.

但是为什么呢?到底为什么会崩溃? Parent-Column 位于 Scaffoldbody 内。

我在这里缺少什么?

如果您需要更多信息,请告诉我!

最佳答案

这是因为内列对其高度没有任何限制,因此 Spacer 小部件可以占据无限大的空间。您可以通过使用 Expanded(或任何其他高度约束小部件,如 SizedBox)包装内列的高度来设置实际约束:

Column(
children: [
Expanded(
child: Column(
children: [
Text('No'),
Spacer(),
Text('crash!'),
],
),
),
Text('ok'),
],
),

关于如果在另一个列内的列中使用间隔器,则会出现 flutter 无界高度错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70177056/

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