有没有办法动态更改 Flutter TextField 的 maxLines?
Is there a way to dynamically change the Flutter TextField's maxLines?
我有一个这样的 TextField:
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),
),
),
),
我想让我的 TextField 以 maxLines
设置为 1 开始,但是在我键入时,我希望 maxLines 增加,以便所有文本都保留在页面上,我不必向上滚动。但是,我也不想一开始就将 maxLines
设置为 5 或 10,因为空的 TextField 占用了更多 space 所需的空间。我想要实现的行为示例是 Google Forms 中的 Long Answer Text 选项,它以一行开头:
并在我键入时展开:
我考虑过将 maxLines
设置为一个计数器,该计数器在用户每次点击换行符时递增,但我如何确定用户何时填满了一行?
Flutter 在 TextField 中落后于多行支持。 issue was raised regarding the same, the multiline feature has been added in the 0.0.16 发布后。
确保将 flutter 升级到最新版本。要获得多行 TextField,请使用:
new TextField(
maxLines: null,
keyboardType: TextInputType.multiline,
)
希望对您有所帮助!
它看起来像 text-area。你可以试试 maxLines
maxLines: 8
TextField(
maxLines: 8,
decoration: InputDecoration(hintText: "Enter your text here", border: OutlineInputBorder(),
labelText: 'Post Body'),
),
我有一个这样的 TextField:
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),
),
),
),
我想让我的 TextField 以 maxLines
设置为 1 开始,但是在我键入时,我希望 maxLines 增加,以便所有文本都保留在页面上,我不必向上滚动。但是,我也不想一开始就将 maxLines
设置为 5 或 10,因为空的 TextField 占用了更多 space 所需的空间。我想要实现的行为示例是 Google Forms 中的 Long Answer Text 选项,它以一行开头:
我考虑过将 maxLines
设置为一个计数器,该计数器在用户每次点击换行符时递增,但我如何确定用户何时填满了一行?
Flutter 在 TextField 中落后于多行支持。 issue was raised regarding the same, the multiline feature has been added in the 0.0.16 发布后。
确保将 flutter 升级到最新版本。要获得多行 TextField,请使用:
new TextField(
maxLines: null,
keyboardType: TextInputType.multiline,
)
希望对您有所帮助!
它看起来像 text-area。你可以试试 maxLines
maxLines: 8
TextField(
maxLines: 8,
decoration: InputDecoration(hintText: "Enter your text here", border: OutlineInputBorder(),
labelText: 'Post Body'),
),