【问题标题】:How to make Flutter TextField accept multiline?如何让 Flutter TextField 接受多行?
【发布时间】:2019-03-01 10:12:34
【问题描述】:

如何让 Flutter TextField 接受多行?以下代码不起作用:

body: Padding(
    child: Column(
        children: [
            Text('BIO'),
            Expanded(
                child: TextField(
                    autofocus: false,
                    controller: _text,
                    // https://stackoverflow.com/a/46767771
                    keyboardType: TextInputType.multiline,
                    maxLength: null,
                ),
            ),
        ],
        crossAxisAlignment: CrossAxisAlignment.start,
    ),
    padding: const EdgeInsets.all(8),
),

(稍后,我将删除蓝色下划线,它只是显示它是 1-liner)。

我正在使用频道管理员,v1.2.3-pre.66。

【问题讨论】:

    标签: flutter flutter-layout


    【解决方案1】:
    TextField(
      keyboardType: TextInputType.multiline,
      maxLength: null,
      maxLines: null,
    )
    

    您只需将maxLines 设置为空

    【讨论】:

      【解决方案2】:

      给属性 maxLines: nullTextField 小部件

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

      【讨论】:

        【解决方案3】:

        只需将 maxLines 设置为 null:

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

        如果maxLines属性为null,则不限制行数,并启用换行。

        你也可以通过添加来设置最小线

        minLines: 2    //Number of lines(int), you can replace with your number as per your need
        

        【讨论】:

          猜你喜欢
          • 2019-01-25
          • 1970-01-01
          • 1970-01-01
          • 2016-09-01
          • 2011-06-28
          • 2020-07-12
          • 2020-03-03
          • 2020-05-12
          • 2019-11-17
          相关资源
          最近更新 更多