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

問題:

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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章