Flutter - 文本字段添加新行
Flutter - Textfield add new line
我尝试用 keyboardType: TextInputType.visiblePassword
创建一个 TextField 来禁用预测文本,但是我不能换行,因为它是一个提交按钮。我尝试添加 textInputAction: TextInputAction.newline
但也不起作用。
我的文本字段:
TextField(
focusNode: myFocusNode,
autocorrect: false,
enableSuggestions: false,
toolbarOptions: ToolbarOptions(copy: false, cut: false, paste: false),
keyboardType: TextInputType.visiblePassword,
textInputAction: TextInputAction.newline,
autofocus: true,
maxLines: null,
controller: textEditor,
decoration: InputDecoration(fillColor: Colors.grey[100])
))));
将TextInputAction.newline更改为TextInputAction.next
TextField(
focusNode: myFocusNode,
autocorrect: false,
enableSuggestions: false,
toolbarOptions: ToolbarOptions(copy: false, cut: false, paste: false),
keyboardType: TextInputType.visiblePassword,
textInputAction: TextInputAction.newline,
autofocus: true,
maxLines: null,
controller: textEditor,
decoration: InputDecoration(fillColor: Colors.grey[100])
))));
您只需添加以下参数即可禁用预测文本。
enableSuggestions: false,
autocorrect: false,
但要启用多行,您需要将'keyboardType'更改为'TextInputType.multiline'。
TextField(
autocorrect: false,
enableSuggestions: false,
toolbarOptions: ToolbarOptions(copy: false, cut: false, paste: false),
keyboardType: TextInputType.multiline,
textInputAction: TextInputAction.newline,
autofocus: true,
maxLines: null,
decoration: InputDecoration(fillColor: Colors.grey[100]))
我在 RawKeyboardListener 中添加了我的文本字段,当用户按下“Enter”时它会自动检测到。
RawKeyboardListener(
focusNode: FocusNode(),
onKey: (event) {
if(event.isKeyPressed(LogicalKeyboardKey.enter)) {
int cursorPos = textEditor.selection.base.offset;
textEditor.text = textDebut + '\n' + textFin;
textEditor.selection = TextSelection.fromPosition(TextPosition(offset: cursorPos + 1));}},
child:TextField(
focusNode: myFocusNode,
autocorrect: false,
enableSuggestions: false,
toolbarOptions: ToolbarOptions(copy: false, cut: false, paste: false),
keyboardType: TextInputType.visiblePassword,
textInputAction: TextInputAction.newline,
autofocus: true,
maxLines: null,
controller: textEditor,
decoration: InputDecoration(fillColor: Colors.grey[100]),
onChanged: (String text) {print(text);}))
我尝试用 keyboardType: TextInputType.visiblePassword
创建一个 TextField 来禁用预测文本,但是我不能换行,因为它是一个提交按钮。我尝试添加 textInputAction: TextInputAction.newline
但也不起作用。
我的文本字段:
TextField(
focusNode: myFocusNode,
autocorrect: false,
enableSuggestions: false,
toolbarOptions: ToolbarOptions(copy: false, cut: false, paste: false),
keyboardType: TextInputType.visiblePassword,
textInputAction: TextInputAction.newline,
autofocus: true,
maxLines: null,
controller: textEditor,
decoration: InputDecoration(fillColor: Colors.grey[100])
))));
将TextInputAction.newline更改为TextInputAction.next
TextField(
focusNode: myFocusNode,
autocorrect: false,
enableSuggestions: false,
toolbarOptions: ToolbarOptions(copy: false, cut: false, paste: false),
keyboardType: TextInputType.visiblePassword,
textInputAction: TextInputAction.newline,
autofocus: true,
maxLines: null,
controller: textEditor,
decoration: InputDecoration(fillColor: Colors.grey[100])
))));
您只需添加以下参数即可禁用预测文本。
enableSuggestions: false,
autocorrect: false,
但要启用多行,您需要将'keyboardType'更改为'TextInputType.multiline'。
TextField(
autocorrect: false,
enableSuggestions: false,
toolbarOptions: ToolbarOptions(copy: false, cut: false, paste: false),
keyboardType: TextInputType.multiline,
textInputAction: TextInputAction.newline,
autofocus: true,
maxLines: null,
decoration: InputDecoration(fillColor: Colors.grey[100]))
我在 RawKeyboardListener 中添加了我的文本字段,当用户按下“Enter”时它会自动检测到。
RawKeyboardListener(
focusNode: FocusNode(),
onKey: (event) {
if(event.isKeyPressed(LogicalKeyboardKey.enter)) {
int cursorPos = textEditor.selection.base.offset;
textEditor.text = textDebut + '\n' + textFin;
textEditor.selection = TextSelection.fromPosition(TextPosition(offset: cursorPos + 1));}},
child:TextField(
focusNode: myFocusNode,
autocorrect: false,
enableSuggestions: false,
toolbarOptions: ToolbarOptions(copy: false, cut: false, paste: false),
keyboardType: TextInputType.visiblePassword,
textInputAction: TextInputAction.newline,
autofocus: true,
maxLines: null,
controller: textEditor,
decoration: InputDecoration(fillColor: Colors.grey[100]),
onChanged: (String text) {print(text);}))