'Cannot remove underside padding from TextField and TextFormField in Flutter
I have this widget:
TextFormField(
controller: _activityName,
autocorrect: true,
textAlign: TextAlign.start,
decoration: InputDecoration(
contentPadding = EdgeInsets.zero,
border: UnderlineInputBorder(
),
hintText: ""),
maxLines: 1,
cursorColor: Colors.white,
),
As you can see I explicitly set the padding to be 0, as this answer said: How do I remove content padding from TextField?
But the result I get is this:
As you can see under the Text MyActivity there is a lot of padding, but I can't get rid of it. It looks like a bug, but I'm not sure:
This is the flutter doctor:
Flutter (Channel stable, v1.12.13+hotfix.5, on Microsoft Windows [Version 10.0.18362.295], locale en-US)
• Flutter version 1.12.13+hotfix.5 %Flutter path%
• Framework revision 27321ebbad (3 weeks ago), 2019-12-10 18:15:01 -0800
• Engine revision 2994f7e1e6
• Dart version 2.7.0
Solution 1:[1]
From https://stackoverflow.com/a/59295394/4465386 - check it out for a demo too.
This is how to get 0 padding textFields:
TextField(
decoration: InputDecoration(
contentPadding: EdgeInsets.all(0),
isDense: true,
),
);
Solution 2:[2]
You can remove a little bit of space by using collapsed:
TextField(
decoration: InputDecoration.collapsed(hintText: null),
),
Solution 3:[3]
Please try this.
TextField(
decoration: InputDecoration(
contentPadding: EdgeInsets.zero,
isDense: true,
),
);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Zvi Karp |
| Solution 2 | Yster |
| Solution 3 | cigien |

