如何使Flutter TextField接受多行输入?

5
如何使Flutter的TextField支持多行输入?以下代码无法实现:
```dart TextField( maxLines: null, ) ```
body: Padding(
    child: Column(
        children: [
            Text('BIO'),
            Expanded(
                child: TextField(
                    autofocus: false,
                    controller: _text,
                    // https://dev59.com/tFYN5IYBdhLWcg3w4bhS#46767771
                    keyboardType: TextInputType.multiline,
                    maxLength: null,
                ),
            ),
        ],
        crossAxisAlignment: CrossAxisAlignment.start,
    ),
    padding: const EdgeInsets.all(8),
),

以后我会去掉蓝色下划线,那只是为了说明这是一行代码。

我使用的是频道主程序,版本号为v1.2.3-pre.66。

Flutter中的多行问题

3个回答

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

你只需要将maxLines设置为null。


3

将属性maxLines: null赋给TextField部件。

TextField(
  autofocus: false,
  controller: _text,
  keyboardType: TextInputType.multiline,
  maxLength: null,
  maxLines: null,
),

2

只需将maxLines设置为null:

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

如果maxLines属性为null,则行数没有限制,并且启用了换行。您可以通过添加min line来设置最小行数。
minLines: 2    //Number of lines(int), you can replace with your number as per your need

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接