Noah-Yannick Schmid
Noah-Yannick Schmid

Reputation: 128

How to align Text properly in flutter?

I actually want to find out how I can center text in a button correctly. I am using a custom font and with this font, it won't center my text inside of the button no matter what I am doing.

I already have found out, that with the standard Font (I guess its Roboto) it's not aligning perfectly in the center too but this isn't very annoying at that point.

Here is my code:

RaisedButton(
   onPressed: () {},
   child: Text("LOG IN"),
),

Here what it produces with my custom font:

enter image description here

And here with standard Roboto:

enter image description here

Thank you very much!

Upvotes: 0

Views: 1568

Answers (3)

Alex Schneider
Alex Schneider

Reputation: 384

If the alignment changes from one font to another it's unlikely to be a padding or flutter related alignment issue as suggested in the other answers.

This can be caused by using a font format that's not properly supported by flutter/android/ios, e.g. I had this exact issue using a font in oft format and using the ttf version fixed it.

This thread from some time ago highlights that this is not properly documented and other formats such as woff2 are also not supported: https://github.com/flutter/flutter/issues/13823

Upvotes: 0

LonelyWolf
LonelyWolf

Reputation: 4392

Try to add padding 0

RaisedButton(
   padding: EdgeInsets.all(0), //<- try add this
   onPressed: () {},
   child: Text("LOG IN"),
),

Upvotes: 1

encubos
encubos

Reputation: 3283

Try to use Center() widget to see what happen

RaisedButton(
   onPressed: () {},
   child: Center(child: Text("LOG IN")),
),

Upvotes: 0

Related Questions