How do I center text vertically and horizontally in Flutter?

后端 未结 8 1315
不思量自难忘°
不思量自难忘° 2020-12-13 05:34

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: T

相关标签:
8条回答
  • 2020-12-13 06:04

    You can use TextAlign property of Text constructor.

    Text("text", textAlign: TextAlign.center,)
    
    0 讨论(0)
  • 2020-12-13 06:04

    Put the Text in a Center:

    Container(
          height: 45,
          color: Colors.black,
          child: Center(
            child: Text(
                'test',
                style: TextStyle(color: Colors.white),
            ),
          ),
        );
    
    0 讨论(0)
提交回复
热议问题