Multi-line Textfield in flutter

后端 未结 11 1712
夕颜
夕颜 2020-12-13 07:54

It may sound easy but How can we do a multi-line editable textfield in flutter? TextField works only with a single line.

Edit: some precisions beca

相关标签:
11条回答
  • 2020-12-13 08:17

    if above once not worked for you then try add minLines also

    TextField(
            keyboardType: TextInputType.multiline,
            minLines: 3,
            maxLines: null);
    
    0 讨论(0)
  • 2020-12-13 08:17

    Specify TextInputAction.newline to make a TextField respond to the enter key and accept multi-line input:

    textInputAction: TextInputAction.newline,
    
    0 讨论(0)
  • 2020-12-13 08:18

    If you want that your TextField should adapt to the user input then do this:

    TextField(
        keyboardType: TextInputType.multiline,
        minLines: 1,//Normal textInputField will be displayed
        maxLines: 5,// when user presses enter it will adapt to it
        );
    

    here set the max lines to whatever you want and you are good to go. In my opinion setting the maxlines to null is not a good choice we should set it to some value.

    0 讨论(0)
  • 2020-12-13 08:18

    TextField has maxLines property.

    0 讨论(0)
  • 2020-12-13 08:26

    To use auto wrap, just set maxLines as null:

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

    If the maxLines property is null, there is no limit to the number of lines, and the wrap is enabled.

    0 讨论(0)
  • 2020-12-13 08:26

    Official doc states: The maxLines property can be set to null to remove the restriction on the number of lines. By default, it is one, meaning this is a single-line text field.

    NOTE: maxLines must not be zero.

    0 讨论(0)
提交回复
热议问题