如何在Flutter中居中对齐文本?

时间:2019-05-21 03:23:34

标签: fonts flutter

预期输出:

I want the output to be like this.

我当前的输出:

Currently it's like this

当前输出的代码:

subtitle: Center(child: Text(
                    "Hello, my name is Sam \n I am new here.",
                    style: TextStyle(fontSize: 18, color: Colors.white),
                  ),
                ),

2 个答案:

答案 0 :(得分:1)

您可以使用属性Text来设置textAlign对齐方式:

Text(
  "Hello, my name is Sam \n I am new here.",
  textAlign: TextAlign.center,
  style: TextStyle(fontSize: 18, color: Colors.white),
);

答案 1 :(得分:0)

使用textAlign

subtitle: Center(child: Text(
                    "Hello, my name is Sam \n I am new here.",
                    textAlign: TextAlign.center,
                    style: TextStyle(fontSize: 18, color: Colors.white),
                  ),
                ),