多行文本与行高垂直居中对齐

问题描述

我目前正在尝试让文本以特定的行高应用并将文本垂直居中对齐。由于 TextStyle 上没有垂直对齐的选项,我尝试使用 StrutStyle 并导致 大约 将其与中心对齐。但是设置了行距后,行距和带有TextStyle高度的Text的高度是不一样的。

演示可以在dartpad查看。

    Text(
      'label A',style: const TextStyle(
        fontSize: 16.0,color: Colors.red,backgroundColor: Colors.blue,),strutStyle: StrutStyle(
        fontSize: 16.0,leading: (70.0 / 16.0)/2,forceStrutHeight: true,
  1. 想问一下有没有什么合适的方法可以将其居中对齐?文本是多行
  2. 如果现在这种情况推荐使用领先的方法,是否有任何计算可以使用领先同步正确的高度?

解决方法

Wrap With Align Widget 这将帮助您随心所欲地对齐。

 Align (
      alignment : Alignment.topCenter;
    child : Text(
          'label A',style: const TextStyle(
            fontSize: 16.0,color: Colors.red,backgroundColor: Colors.blue,),strutStyle: StrutStyle(
            fontSize: 16.0,leading: (70.0 / 16.0)/2,forceStrutHeight: true,

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...