Skip to content
DeveloperMemos

How to Center Align a Text Widget's text

Flutter, Dart, Text1 min read

The other day I ran into a situation where I had wanted to center align the text in a Flutter Text widget and I couldn't figure out how to do it immediately. In the past I had done things like wrapping the Text widget in a Center widget but if you're just trying to horizontally center(vertically is a different story) text there's actually a much better, cleaner way to do it.

So as it turns out, the Text widget in Flutter actually has an align property and you can use this to align the text inside the Text widget a certain way. For centering the text horizontally, this is how you would use it:

1Text(
2 "Some Text",
3 textAlign: TextAlign.center,
4)

The TextAlign enum also has a range of other values that you can use for alignment, here's the other options:

1TextAlign.end
2TextAlign.justify
3TextAlign.left
4TextAlign.right
5TextAlign.start

Alternatively if you're looking for a way to completely center the text(vertically and horizontally) you may want to look at combining this approach with a Center or a Column widget. If you use a Column widget keep in mind that you'll have to play around with the axis alignment values.