How do I only apply padding to the text in a TextField in Flutter?
Works for me:
TextFormField(
decoration: InputDecoration(
border: InputBorder.none,
contentPadding: EdgeInsets.symmetric(vertical: 10), //Change this value to custom as you like
isDense: true, // and add this line
hintText: 'User Name',
hintStyle: TextStyle(
color: Color(0xFFF00),
)),
keyboardType: TextInputType.text,
style: TextStyle(
color: Color(0xFFF00),
fontSize: 14),
maxLines: 1,
)
To apply the padding to the content of the TextField
. You can apply the
contentPadding property of ItemDecoration at decoration property of TextField.
Like this:
TextField(
textAlign: TextAlign.left,
decoration: InputDecoration(
hintText: 'Enter Something',
contentPadding: EdgeInsets.all(20.0),
),
)
If you want to apply uneven, vertical padding to each side of the text inside the TextField, you'll have to first set textAlignVertical to TextAlignVertical.top.
If you don't do this, the largest top/bottom padding will apply to both the top and bottom of the text. I'm guessing this is because the TextField text is always centered horizontally.
TextField(
controller: model.captionController,
maxLines: null,
minLines: 8,
maxLength: 200,
textAlignVertical: TextAlignVertical.top,
decoration: PostFilledField('Add a caption...').copyWith(
contentPadding: EdgeInsets.fromLTRB( 8, 0, 8, 90.0),
isDense: true
),
style: PostSmallText(),
),