flutterdarttextfield

Flutter - Textfield add new line


I try to make a TextField with keyboardType: TextInputType.visiblePassword to disable the predictive text but with that I can't go to a new line because it's a submit button. I try to add textInputAction: TextInputAction.newline but don't work too.

My TextField:

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])
))));

Solution

  • I add my textfield in a RawKeyboardListener and when user press "Enter" it's detect automatically.

    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);}))