Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multi-line Textfield in flutter

Tags:

flutter

dart

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.

like image 453
Rémi Rousselet Avatar asked Aug 26 '17 23:08

Rémi Rousselet


People also ask

How do I create a multiline TextField in Flutter?

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.


2 Answers

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.

like image 144
Fellipe Sanches Avatar answered Sep 23 '22 17:09

Fellipe Sanches


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.

like image 32
taranjeet singh Avatar answered Sep 23 '22 17:09

taranjeet singh