我遇到了一个渲染异常,我不知道如何修复.我正在try 创建一个包含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相关问答推荐

try 在Flutter应用程序中传递变量到FirebaseFirestore Where子句

我不能通过第5步了解Flutter 翼Firebase教程

Flutter -如何停止块监听程序在后台堆栈中运行

CLI数据库连接后将SHA-1密钥添加到Firebase项目

在Flutter TextField中计算子字符串位置

在框中保存对象列表时,类型推断无法正常工作

Flutter API请求BadState响应

如何删除使用isscllable时出现的左边距?

参数类型void Function()无法分配给参数类型void Function(LongPressEndDetails)?

在 Flutter 中使用条件语句设置 ImageProvider Object 类型的背景图像

找不到任何与 com.google.firebase:firebase-sessions:[15.0.0, 16.0.0) 匹配的版本

模块是使用不兼容的 kotlin 版本编译的.其元数据的二进制版本是1.8.0,预期版本是1.6

为什么我们使用 RiverpodGenerator

将状态维护到 asyncNotifier

Flutter 动画页面计数器文本

在 flutter 中使用 Firebase 实时数据库数据创建无限滚动效果

我可以使用 Future 来填充Text() 小部件而不是在 Flutter 中使用 FutureBuilder 吗?

如何判断 text.contains() 是否包含多个值

如何在dart中编写多个条件?

参数类型MaterialPageRoute不能分配给参数类型String