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 because seems like it's not clear. While you can set multiline to virtually wrap the text content, it's still not multiline. It's a single line displayed into multiple lines. If you want to do something like this then you can't. Because you don't have access to ENTER
button. And no enter button means no multiline.
So to make a TextField accept multiple lines, simply make use of maxLines property in TextField or TextFormField widget. And keyboardType property set it to TextInputType. multiline, so that user will get a button using which he/she can move the cursor to next line.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With