I'd like to know how to center the contents of 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. By default, it's aligned to the left. In Android, I believe the property of a TextView that achieves this is called gravity.
Center(child: Text("test"))
gravity
Example of what I want:
Text alignment center property setting only horizontal alignment.
I used below code to set text vertically and horizontally center.
Code:
child: Center( child: Text( "Hello World", textAlign: TextAlign.center, ), ),
2.1m questions
2.1m answers
60 comments
57.0k users