5

How to make Flutter TextField accept multiline? The following code does NOT work:

body: Padding(
    child: Column(
        children: [
            Text('BIO'),
            Expanded(
                child: TextField(
                    autofocus: false,
                    controller: _text,
                    // https://stackoverflow.com/a/46767771
                    keyboardType: TextInputType.multiline,
                    maxLength: null,
                ),
            ),
        ],
        crossAxisAlignment: CrossAxisAlignment.start,
    ),
    padding: const EdgeInsets.all(8),
),

(Later, I will remove the blue underline, it's just there to show that it's a 1-liner).

I'm on channel master, v1.2.3-pre.66.

Multiline problem in Flutter

wiradikusuma
  • 1,930
  • 4
  • 28
  • 44

3 Answers3

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

All you need is to set maxLines to null

Nipun
  • 990
  • 1
  • 16
  • 25
3

Give the property maxLines: null to the TextField widget

TextField(
  autofocus: false,
  controller: _text,
  keyboardType: TextInputType.multiline,
  maxLength: null,
  maxLines: null,
),
krishnakumarcn
  • 3,959
  • 6
  • 39
  • 69
2

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.

And you can set min line also by adding

minLines: 2    //Number of lines(int), you can replace with your number as per your need
Nikhat Shaikh
  • 3,175
  • 1
  • 16
  • 21