Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I remove content padding from TextField?

I am new to flutter and I am creating login form, for that I have used TextField and added prefix icon but I am getting some extra spaces in between textfields (user id and pin) and before the prefix icon. I have also tried InputDecorationTheme but it didn't work.

Please let me know how can I remove or reduce the space.??

Below is my code:

TextField(   maxLength: 8,   keyboardType: TextInputType.number,   decoration: InputDecoration(     hintText: hint,     hintStyle: TextStyle(fontSize: 12.0),     prefixIcon: Icon(icon),     counterText: '',   ), ) 

x

like image 369
Zubair Rehman Avatar asked Dec 06 '18 04:12

Zubair Rehman


People also ask

How do you get rid of the TextField padding in Flutter?

As of flutter 1.17. 5 (and still the same in 2. X) to completely remove or manipulate the padding manually, first you must set isDense: true and then you can adjust the contentPadding as you wanted or apply padding on the parent widget instead. TextField has not an inputDecorationTheme attribute.

How do I get rid of maxLength in TextField Flutter?

To hide counter value from TextField or TextFormField widget while using maxLength attribute, try following: TextField( decoration: InputDecoration( hintText: "Email", counterText: "", ), maxLength: 40, ), In this, I have set counterText attribute inside InputDecoration property with empty value. Hope it will help.

How do you change the padding in TextField in Flutter?

You can set the inner padding of a TextField by using the contentPadding property of the InputDecoration class.


2 Answers

Update (April 2021): still work in flutter 2.0.4

As of flutter 1.17.5 (and still the same in 1.2X) to completely remove or manipulate the padding manually, first you must set isDense: true and then you can adjust the contentPadding as you wanted or apply padding on the parent widget instead.

// using theme ThemeData(   inputDecorationTheme: InputDecorationTheme(      isDense: true,// this will remove the default content padding      // now you can customize it here or add padding widget      contentPadding: EdgeInsets.symmetric(horizontal: 0, vertical: 0),      ...   ), )  // per widget TextField(    decoration: InputDecoration(    isDense: true,    contentPadding: EdgeInsets.symmetric(horizontal: 0, vertical: 0),    ...  ), ) 
like image 150
Alexander Dischberg Avatar answered Sep 21 '22 01:09

Alexander Dischberg


You can use contentPadding of InputDecoration. Here is sample code

TextField(    maxLines: 8,    decoration: InputDecoration(       contentPadding: EdgeInsets.symmetric(vertical: 5),       labelText: 'Description',       labelStyle: txtHintStyle,    )  ) 
like image 33
Ketan Ahir Avatar answered Sep 21 '22 01:09

Ketan Ahir