How do set text line height in flutter?

荒凉一梦 提交于 2020-08-27 21:40:49

问题


So in Material Design Spec under Onboarding: here

It is specified that:

32sp line height

which is the height from the bottom of the headline text to the base line of the subhead text.

My question is how exactly can this be implemented in flutter. Are padding enough to mimic this spec? or are there other more accurate ways to do this?


回答1:


Yes, there is also a height property in TextStyle which allows you to manually adjust the height of the line.

Code Snippet

Text('Hey There', 
  style: TextStyle(height: 5, fontSize: 10),
)




回答2:


In addition to Ayush answer. I f we look to the documentation, we can see

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.

For example, if want to have height 24.0, with font-size 20.0, we should have height property 1,2.

Example:

TextStyle(
      fontSize: 20.0,
      height: 1.2,
);


来源:https://stackoverflow.com/questions/58156806/how-do-set-text-line-height-in-flutter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!