23.3 C
New York
Wednesday, August 17, 2022

Flutter: Creating an Auto-Resize TextField

- Advertisement -

In Flutter, you can create an auto-resize as needed TextField (or TextFormField) in one of the following ways:

  • Set the maxlines argument to null. The textfield can expand forever if a lot of text is entered.
  • Set minLines to 1 and maxLines to N (a possitive integer). The textfield will auto expand or shrink based on the length of the entered text. It will stop expanding and start scrolling if it reaches N lines.

The example below will demonstrate the second approach.Advertisements

Example Preview:

The code:

Scaffold(
      appBar: AppBar(
        title: const Text('KindaCode.com'),
      ),
      body: const Padding(
        padding: EdgeInsets.all(30),
        child: Center(
          child: TextField(
            minLines: 1,
            maxLines: 10,
            style: TextStyle(fontSize: 20),
            decoration: InputDecoration(border: OutlineInputBorder()),
          ),
        ),
      ),
    );

Further reading:

AdvertisementsYou can also take a tour around our Flutter topic page and Dart topic page to see the latest tutorials and examples.

Advertisements
- Advertisement -

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles