如何在卡上创建TextField

时间:2018-05-23 08:48:35

标签: flutter

如何在卡片上创建TextField。 在功能中我返回一张卡片。在这里,我需要实现一个TextField。 这是我的代码:

return new Card(
        color: Colors.white70,
        child: new Container(
          padding: EdgeInsets.all(10.0),
          child: new Column(
            children: <Widget>[
              new Row(
                children: <Widget>[
                  new Expanded(child: new Text("Bemerkung", style: style,)),
                  new TextField(

                  ),
                ],
              ),
            ],
          ),
        ),
      );

每次我想调试时,都抛出了这个异常:

I/flutter (17588): ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
I/flutter (17588): The following assertion was thrown during performLayout():
I/flutter (17588): BoxConstraints forces an infinite width.
I/flutter (17588): These invalid constraints were provided to RenderRepaintBoundary's layout() function by the
I/flutter (17588): following function, which probably computed the invalid constraints in question:
I/flutter (17588):   _RenderDecoration._layout.layoutLineBox (package:flutter/src/material/input_decorator.dart:747:11)
I/flutter (17588): The offending constraints were:
I/flutter (17588):   BoxConstraints(w=Infinity, 0.0<=h<=Infinity)

我不知道为什么它没有用。

1 个答案:

答案 0 :(得分:0)

使用Expanded小部件包装TextField,

new Card(
        color: Colors.white70,
        child: new Container(
          padding: EdgeInsets.all(10.0),
          child: new Column(
            children: <Widget>[
              new Row(
                children: <Widget>[
                  new Expanded(child: new Text("Bemerkung",)),
                  new Expanded(
                    child: new TextField(

                    ),
                  ),
                ],
              ),
            ],
          ),
        ),
      );