DEV Community

Cover image for How to Change TextField Height and Width in Flutter?
Kuldeep Tarapara
Kuldeep Tarapara

Posted on • Originally published at bosctechlabs.com

How to Change TextField Height and Width in Flutter?

What is the TextField field?

The most popular text input widget that enables users to import keyboard inputs into an app is TextField in Flutter.

An input element called a TextField or TextBox stores alphanumeric information such as name, password, address, etc. It is a GUI control element that lets users enter text using programmable code.

The problem faces in TextField

When you add a TextField to your page, its default width and height are configured to cover the maximum lines of text its parent enabled.

By default, the TextField height is dependent on the text font size, And its width is your device’s screen width.

Checkout the latest guide on how to use hexadecimal color strings in Flutter?

Set the height of TextField

There are three different ways to adjust the height of a TextField. You can use the MaxLines-MinLines property to increase TextField’s total height when new text is input, and you can use the Font Size and Content Padding to increase the height and enable single-line content.

Change the font size to increase TextField’s height.

In TextField there is a property style:TextStyle();

Inside the textstyle there is a property called font size. Then give the appropriate font size.

TextField(
 decoration: InputDecoration(
   border: OutlineInputBorder(),
   labelText: 'Please search here ',
 ),
 style: TextStyle(fontSize: 25),
),
Enter fullscreen mode Exit fullscreen mode

Output:

Image description

Add padding of text to increase TextField’s height

In InputDecoration() there is a property called contentPadding:

TextField(
 decoration: InputDecoration(
     labelText: 'Please search here ',
     contentPadding: EdgeInsets.all(25),
   border: OutlineInputBorder(),
 ),
 style: TextStyle(fontSize: 25),
),
Enter fullscreen mode Exit fullscreen mode

Output

Image description

Maxine’s-MinLines property to increase TextField’s height

If you want to increase the height of the TextField with the extended text entered, you can use the MaxLines and MinLines properties.

TextField(
 decoration: InputDecoration(
   labelText: 'Please search here ',
   contentPadding: EdgeInsets.all(8),
   border: OutlineInputBorder(),
 ),
 style: TextStyle(fontSize: 25),
 maxLines: 3,
 minLines: 2,
),
Enter fullscreen mode Exit fullscreen mode

Output

Image description

Changing TextField Width
To set the TextField width, you can wrap your TextField inside the SizedBox widget and give the width.

SizedBox(
 width: 250,
 child: TextField(
   decoration: InputDecoration(
     labelText: 'Please search here ',
     contentPadding: EdgeInsets.all(8),
     border: OutlineInputBorder(),
   ),
   style: TextStyle(fontSize: 25),
   maxLines: 3,
   minLines: 2,
 ),
),
Enter fullscreen mode Exit fullscreen mode

Output

Image description

Conclusion

So, far we have learned that how you can change height and width in Flutter with the help of the TextField widget. We learned a use of TextField widget that is specially using to set a height and width of the text field where user fill their input.

Top comments (0)