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: '', ), )
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.
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.
You can set the inner padding of a TextField by using the contentPadding property of the InputDecoration class.
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), ... ), )
You can use contentPadding
of InputDecoration. Here is sample code
TextField( maxLines: 8, decoration: InputDecoration( contentPadding: EdgeInsets.symmetric(vertical: 5), labelText: 'Description', labelStyle: txtHintStyle, ) )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With