Skip to main content

Create Multiline TextField In Flutter

In this snippet, we will look at creating a multiline text field in Flutter. A multiline Textfield is a text field widget that allows the user to input multiple lines of text.

To create a multiline text field, use the TextField widget. The TextField widget has a maxLines property that allows you to specify the maximum number of lines the Textfield can have.

TextField(
    maxLines: 5
)
//allow the field to incease height if input text exceeds maxLines
TextField( 
    maxLines: 3
    expands: true, 
)
//set fixed height for text field with minLines
TextField(
    controller: _controller,
    minLines: 3,
    maxLines: 5,
    decoration: const InputDecoration(label: Text("URLs")),
),
//add ellipsis if text exceeds the field's height
Text('line 1\nline 2\nline 3\nline 4\nline 5', maxLines: 4,
       overflow: TextOverflow.ellipsis,
       textDirection: TextDirection.rtl,
       textAlign: TextAlign.justify,
),

By continuing to use the site, you agree to the use of cookies.