Paul Rangger
Paul Rangger

Reputation: 97

TextField hint/input text not centered without prefixIcon after update to Flutter 1.12.13

I created TextFields with a custom height and a different background color. Here is the code snippet:

Container(
  width: width,
  height: 35,
  decoration: BoxDecoration(
    color: Constants.greyColor,
    borderRadius: BorderRadius.all(Radius.circular(2)),
  ),
  padding: EdgeInsets.symmetric(horizontal: 15),
  child: TextField(
    textAlign: descriptor == null ? TextAlign.center : TextAlign.left,
    decoration: InputDecoration(
      hintText: placeholder,
      hintStyle: Constants.textStyleTextInputHint,
      border: InputBorder.none,
      contentPadding: EdgeInsets.symmetric(horizontal: 0),
    ),
    onChanged: (value) {
      state.didChange(value);
    },
    obscureText: isPassword,
    style: Constants.textStyleTextInput,
    cursorColor: Constants.primaryColor,
  ),
),

It worked fine until I recently updated Flutter to version 1.12.13+hotfix.5. Now the hint text as well as the input text are not centered anymore. It seems as if the Container does not change the height of the TextField anymore. Like so:

TextField with hint text being offset

If I add a prefixIcon the text and the icon will get perfectly centered. Like so:

TextField with prefixIcon

Does anybody know how I can center the text without an Icon?

Thank you!

Upvotes: 2

Views: 1756

Answers (1)

Federick Jonathan
Federick Jonathan

Reputation: 2864

I think it's because you add a contentPadding property, even tho it's only horizontal. Have you tried removing it?

TextField(
  textAlign: TextAlign.center
  decoration: InputDecoration(
    hintText: ...,
    hintStyle: ...,
    border: ...,
    // contentPadding:
  )
)

Upvotes: 3

Related Questions