Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make Flutter TextField accept multiline?

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

like image 596
wiradikusuma Avatar asked Nov 29 '22 21:11

wiradikusuma


2 Answers

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

All you need is to set maxLines to null

like image 138
Mohamed hassan kadri Avatar answered Dec 05 '22 18:12

Mohamed hassan kadri


Give the property maxLines: null to the TextField widget

TextField(
  autofocus: false,
  controller: _text,
  keyboardType: TextInputType.multiline,
  maxLength: null,
  maxLines: null,
),
like image 39
krishnakumarcn Avatar answered Dec 05 '22 20:12

krishnakumarcn