这可能听起来容易,但我们如何能做一个多行可编辑的文本域颤振?TextField只与单行工作。

编辑:一些精确度,因为看起来不清楚。 虽然您可以将multiline设置为虚拟换行文本内容,但它仍然不是多行。它是一行显示成多行。 如果你想做这样的事,那就不行。因为你没有回车键。没有回车键就没有多路线路。


当前回答

官方文件指出: maxLines属性可以设置为null,以消除对行数的限制。默认情况下,它是1,这意味着这是一个单行文本字段。

注意:maxLines不能为零。

其他回答

你必须在TextField小部件中使用这一行:

maxLines: null,

如果没有工作,请注意,你必须删除这个:

textInputAction: TextInputAction.next

它是禁用多行属性动作在键盘..

如果你想要你的TextField是适应用户输入,然后这样做:

TextField(
    keyboardType: TextInputType.multiline,
    minLines: 1,//Normal textInputField will be displayed
    maxLines: 5,// when user presses enter it will adapt to it
    );

在这里,你可以将Max行设置为任何你想要的,你就可以开始了。 在我看来,将maxlines设置为null不是一个好的选择,这就是为什么我们应该将它设置为一些值。

TextField有maxLines属性。

这段代码为我工作,我也能够使用ENTER的网页和移动。

@override
  Widget build(BuildContext context) {
      double width = MediaQuery.of(context).size.width;
      double height = MediaQuery.of(context).size.height;
    return Row(
      crossAxisAlignment: CrossAxisAlignment.start, 
      children: [
      Container(
        child: ConstrainedBox(
          //  fit: FlexFit.loose,
          constraints:  BoxConstraints(
            maxHeight: height,//when it reach the max it will use scroll
            maxWidth: width,
          ),
          child: const TextField(
            keyboardType: TextInputType.multiline,
            maxLines: null,
            minLines: 1,
            decoration: InputDecoration(
              fillColor: Colors.blueAccent,
              filled: true,
              hintText: "Type  ",
              border: InputBorder.none,
            ),
          ),
        ),
      )
    ]);
  }

要使用自动换行,只需将maxLines设置为null:

TextField(
  keyboardType: TextInputType.multiline,
  maxLines: null,
)

如果maxLines属性为空,则没有行数限制,并且启用换行。