TextField inside of Row causes layout exception: Unable to calculate size

10/14 09:09
阅读数 0

问题:

I'm getting a rendering exception that I don't understand how to fix.我收到了一个渲染异常,我不知道如何修复。 I'm attempting to create a column that has 3 rows.我正在尝试创建一个有 3 行的列。

Row [Image]行 [图像]

Row [TextField ]行 [TextField ]

Row [Buttons]行 [按钮]

Here is my code to build the container:这是我构建容器的代码:

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;
  }

and my buildAppEntryRow code for the text 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,
        )
      ],
    );
  }

When I run I get the following exception:当我运行时,出现以下异常:

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)

If i change buildAppEntryRow to just a TextField instead like this如果我将 buildAppEntryRow 更改为 TextField 而不是这样

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

I no longer get the exception.我不再得到例外。 What am I missing with the Row implementation that is causing it to not be able to calculate the size of that row?我在 Row 实现中缺少什么导致它无法计算该行的大小?


解决方案:

参考一: https://en.stackoom.com/question/36x5B
参考二: https://stackoom.com/question/36x5B
展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部