如何在flutter中获得相同的字母大小

问题描述 投票:0回答:1

上下字母的所有设置都是一样的。 然而,随着字母内容的变化,两种尺寸并不匹配。 有办法解决这个问题吗

child: Column(
                mainAxisAlignment: MainAxisAlignment.start,
                children: [
                  Container(height: 9,),
                  Text(
                    '              24.07.23 16:31',
                    style: TextStyle(
                        color: Colors.white,
                        fontWeight: FontWeight.w600,
                        fontSize: 23,
                        fontFamily: "Interop",
                    ),
                  ),
                  Text(
                    '              24.10.15 16:01',
                    style: TextStyle(
                        color: Colors.white,
                        fontWeight: FontWeight.w600,
                        fontSize: 23,
                        fontFamily: "Interop",

                    ),
                  ),
                ],
              ),

enter image description here

我尝试使用textScaleFactor之类的代码来匹配字体大小,但无法解决。

flutter dart
1个回答
0
投票

您的文本具有相同的字体大小:

A digital ruler showing that the text sizes are the same

这里的问题是各个字母具有不同的大小 - 例如

1
0
占用的水平空间更少。

您想要做的是使用

textAlign
-Widget 的
Text()
-属性,如下所示:

Text(
    '24.10.15 16:01',
    style: TextStyle(
        color: Colors.white,
        fontWeight: FontWeight.w600,
        fontSize: 23,
        fontFamily: "Interop",
    ),
    textAlign: TextAlign.justify,
)

有关更多信息,请参阅:如何在颤振列小部件中对齐文本?

另一种方法是将字符串的每个元素作为具有绝对宽度的单独

Text()
小部件。

© www.soinside.com 2019 - 2024. All rights reserved.