How do I center text vertically and horizontally in Flutter?

jeroen-meijer picture jeroen-meijer · May 27, 2018 · Viewed 145k times · Source

I'd like to know how to center the contents a Text widget vertically and horizontally in Flutter. I only know how to center the widget itself using Center(child: Text("test")) but not the content itself, it's by default left aligned. In Android, I believe the property of a TextView that achieves this is called gravity.

Example of what I want:

centered text example

Answer

Shelly Pritchard picture Shelly Pritchard · Nov 21, 2018

Text alignment center property setting only horizontal alignment.

enter image description here

I used below code to set text vertically and horizontally center.

enter image description here

Code:

      child: Center(
        child: Text(
          "Hello World",
          textAlign: TextAlign.center,
        ),
      ),