gpt4 book ai didi

flutter - Row 内的 TextField 导致布局异常 : Unable to calculate size

转载 作者:IT老高 更新时间:2023-10-28 13:48:10 26 4
gpt4 key购买 nike

我遇到了一个我不知道如何修复的渲染异常。我正在尝试创建一个有 3 行的列。

行[图片]

行 [文本字段]

行 [按钮]

这是我构建容器的代码:

Container buildEnterAppContainer(BuildContext context) {
var container = new Container(
padding: const EdgeInsets.all(8.0),
child: new Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
buildImageRow(context),
buildAppEntryRow(context),
buildButtonRow(context)
],
),
);
return container;
}

以及我的文本容器的 buildAppEntryRow 代码

Widget buildAppEntryRow(BuildContext context) {
return new Row(
children: <Widget>[
new TextField(
decoration: const InputDecoration(helperText: "Enter App ID"),
style: Theme.of(context).textTheme.body1,
)
],
);
}

运行时出现以下异常:

I/flutter ( 7674): BoxConstraints forces an infinite width.
I/flutter ( 7674): These invalid constraints were provided to RenderStack's layout() function by the following
I/flutter ( 7674): function, which probably computed the invalid constraints in question:
I/flutter ( 7674): RenderConstrainedBox.performLayout (package:flutter/src/rendering/proxy_box.dart:256:13)
I/flutter ( 7674): The offending constraints were:
I/flutter ( 7674): BoxConstraints(w=Infinity, 0.0<=h<=Infinity)

如果我像这样将 buildAppEntryRow 更改为 TextField

 Widget buildAppEntryRow2(BuildContext context) {
return new TextField(
decoration: const InputDecoration(helperText: "Enter App ID"),
style: Theme.of(context).textTheme.body1,
);
}

我不再得到异常。导致它无法计算该行大小的 Row 实现缺少什么?

最佳答案

(我假设您正在使用 Row,因为您希望将来将其他小部件放在 TextField 旁边。)

Row 小部件想要确定其非灵活子项的固有大小,以便知道它为灵活子项留出了多少空间。但是,TextField 没有固有宽度;它只知道如何将自己的大小调整到其父容器的全宽。尝试将其包装在 FlexibleExpanded 中,以告诉 Row 您希望 TextField 占用剩余空间:

      new Row(
children: <Widget>[
new Flexible(
child: new TextField(
decoration: const InputDecoration(helperText: "Enter App ID"),
style: Theme.of(context).textTheme.body1,
),
),
],
),

关于flutter - Row 内的 TextField 导致布局异常 : Unable to calculate size,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45986093/

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