2017-10-15 130 views
1

我有这样一个文本字段:有没有办法动态改变Flutter TextField的maxLines?

new Flexible(
    fit: FlexFit.loose, 
    child: new Container(
     alignment: FractionalOffset.topLeft, 
     child: new TextField(
      decoration: new InputDecoration(
        hintText: 'Add a note', 
      ), 
      maxLines: 1, 
      onChanged: (value) => _showSaveOptions(value), 
     ), 
    ), 
), 

我希望有我的文本字段与maxLines设置为1开始的,但我打字,我想MAXLINES增加,使所有的文字保留在页面上,我不必向上滚动。不过,我也不想从maxLines开始说5或10,因为空的TextField占用了更多的空间。我想要实现的行为的一个例子是在谷歌表单长的答案文本选项,在那里它与一条线开始: enter image description here 并扩展为I型: enter image description here

我已经考虑设置maxLines到每次用户点击一个换行符时都会增加的计数器,但是如何确定用户何时填满了一行?

回答

2

Flutter在TextField中滞后多行支持。有关issue的提出后,多行功能已添加到0.0.16版本中。

确保您升级到最新版本。要获得多行TextField使用:

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

希望这有助于!

+0

这太好了,谢谢!原来,由于这个[问题](https://github.com/flutter/flutter/issues/12046),我现在不能将maxLines设置为null,但我希望这个解决方案能够正常工作。 – Mary

相关问题