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
I come a bit late, but the only thing you have to do is to use negative padding :
TextField(
decoration: InputDecoration(
contentPadding: EdgeInsets.symmetric(vertical: -5),
labelText: 'Description',
)
)
By applying minus padding by using
transform: Matrix4.translationValues(-10.0, 0.0, 0.0),
put above line inside the icon container
TextFormField(
keyboardType: TextInputType.number,
style: new TextStyle(color: Colors.white, fontSize: 17),
decoration: new InputDecoration(
prefixIcon: Container(
transform: Matrix4.translationValues(-10.0, 0.0, 0.0),
child: Icon(
Icons.vpn_key,
color: Colors.white,
),
),
labelText: "Enter Password",
labelStyle: new TextStyle(color: Colors.white)),
),
You can use contentPadding
of InputDecoration.
Here is sample code
TextField(
maxLines: 8,
decoration: InputDecoration(
contentPadding: EdgeInsets.symmetric(vertical: 5),
labelText: 'Description',
labelStyle: txtHintStyle,
)
)
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.
TextField(
inputDecorationTheme: InputDecorationTheme(
isDense: true,
contentPadding: EdgeInsets.symmetric(horizontal: 0, vertical: 0),
...
),
)
You can try this hack by reducing height of TextField
SizedBox(
height: 44, // set this
child: TextField(),
)
I was able to easily achieve that by adding prefix constraints to the prefixIcon and wrapping the prefixIcon with padding like this
TextFormField(
enabled: true,
decoration: InputDecoration(
prefixIconConstraints:BoxConstraints(minWidth: 23, maxHeight: 20),
prefixIcon: Padding(
padding: const EdgeInsets.only(right: 20),
child: Icon(
Icons.email,
color: clockColor,
),
),
hintText:"Email Address"
hintStyle:TextStyle(color: hintColor, fontSize: 14),
),
),
heres the output,hope this helps