【问题标题】:Can't align a text vertically in a container in flutter无法在颤动的容器中垂直对齐文本
【发布时间】:2020-08-29 09:54:10
【问题描述】:

我已经尝试了here 发布的解决方案,但似乎都不起作用。

        Container(
          child: Center(
            child: Text(
            "Financial Formulas\n",
            textAlign: TextAlign.center,
            style: TextStyle(fontSize: 16),
            ),
          ),
          color: Colors.blue,
          width: 150,
          height: 35,
        ),

【问题讨论】:

  • 使用Financial\nFormulas
  • 删除高度和 "\n" 两者

标签: user-interface flutter text widget alignment


【解决方案1】:

当您在文本中添加\n 时,会多出一行。删除它,您的文本将在中间:

【讨论】:

    【解决方案2】:

    要将文本换行,请使用/n

    在您的情况下,将您的代码更改为以下代码:

       Container(
              child: Center(
                child: Text(
                // Financial will be on a line and Formulas on another line
                "Financial\nFormulas",
                // the text align property tells you how to arrange the texts
                textAlign: TextAlign.center,
                style: TextStyle(fontSize: 16),
                ),
              ),
              color: Colors.blue,
              width: 150,
              height: 35,
            ),
    

    【讨论】:

      猜你喜欢
      • 2020-01-21
      • 2014-02-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-01
      • 2022-01-23
      • 2021-01-30
      相关资源
      最近更新 更多