无限宽度约束 - Flutter

Unbounded Width Constraints - Flutter

我正在开发 Flutter 应用,运行 遇到了 Unbounded Width Constraints 错误。这是完整的错误消息:

RenderFlex children have non-zero flex but incoming width constraints are unbounded.
When a row is in a parent that does not provide a finite width constraint, for example if it is in a
horizontal scrollable, it will try to shrink-wrap its children along the horizontal axis. Setting a
flex on a child (e.g. using Expanded) indicates that the child is to expand to fill the remaining
space in the horizontal direction.
These two directives are mutually exclusive. If a parent is to shrink-wrap its child, the child
cannot simultaneously expand to fit its parent.
Consider setting mainAxisSize to MainAxisSize.min and using FlexFit.loose fits for the flexible
children (using Flexible rather than Expanded). This will allow the flexible children to size
themselves to less than the infinite remaining space they would otherwise be forced to take, and
then will cause the RenderFlex to shrink-wrap the children rather than expanding to fit the maximum
constraints provided by the parent.

  parentData: offset=Offset(0.0, 0.0) (can use size)
  constraints: BoxConstraints(0.0<=w<=1298.0, 0.0<=h<=827.0)
  size: MISSING
  direction: vertical
  mainAxisAlignment: start
  mainAxisSize: max
  crossAxisAlignment: center
  verticalDirection: down

这是损坏的代码:

Column(
  children: [
    Container(
      child: Row(
        children: [
          Column(children: formFieldGroupChildren),
        ],
      ),
    ),
  ],
);

这是一个有效的例子:

Column(
  children: [
    Container(
      child: Column(children: formFieldGroupChildren),
    )
  ],
);

Row 小部件似乎没有受到限制,但我不确定如何克服该错误。在包装 Container 上设置宽度和高度限制似乎也无济于事。我需要将另一个元素放在 Column(children: formFieldGroupChildren) 的右侧,这就是为什么我需要 Row 元素,但似乎我在实现中遗漏了一些东西。关于是什么原因造成的任何想法?感谢 advacned!

尝试添加 IntrinsicHeight 以适合您的 formFieldGroupChildren 中最高的。

Column(
      children: [
        Container(
          child: IntrinsicHeight(
            child: Row(
              crossAxisAlignment: CrossAxisAlignment.stretch,
              children: [
                Expanded(child: Column(children: formFieldGroupChildren)),
              ],
            ),
          ),
        ),
      ],
    );