如何在颤振中设置文本行高?

Arc*_*nes 26 material-design flutter

所以在 Onboarding 下的 Material Design Spec 中:这里

明确规定:

32sp 线高

这是从标题文本底部到副标题文本基线的高度。

我的问题是如何在颤振中实现这一点。填充足以模仿这个规范吗?或者有其他更准确的方法来做到这一点?

这里

Ayu*_*ani 45

是的,还有一个height属性TextStyle允许您手动调整线的高度。

代码片段

Text('Hey There', 
  style: TextStyle(height: 5, fontSize: 10),
)
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

  • 根据我的观察,“高度”并没有定义行之间的高度。相反,它定义文本可绘制区域的高度。这意味着如果它太小,那么字母就会被裁剪。 (4认同)

awa*_*aik 27

除了Ayush的回答。如果我们查看文档,我们可以看到

When height is non-null, the line height of the span of text will be a multiple of fontSize and be exactly fontSize * height logical pixels tall.

例如,如果想要高度为 24.0,字体大小为 20.0,我们应该有高度属性 1,2。

例子:

TextStyle(
      fontSize: 20.0,
      height: 1.2,
);
Run Code Online (Sandbox Code Playgroud)