如何在Text
小部件内的flutter中给文本加下划线?
在TextStyle
的fontStyle
属性中似乎找不到下划线
发布于 2019-01-18 09:14:06
在为所有内容加下划线时,您可以在文本小部件上设置TextStyle。
Text(
'Hello world',
style: TextStyle(
decoration: TextDecoration.underline,
),
)
如果只想给文本的一部分加下划线,那么需要使用Text.rich()
(或RichText小部件)并将字符串拆分为TextSpans,您可以向其中添加样式。
Text.rich(
TextSpan(
text: 'Hello ',
style: TextStyle(fontSize: 50),
children: <TextSpan>[
TextSpan(
text: 'world',
style: TextStyle(
decoration: TextDecoration.underline,
)),
// can add more TextSpans here...
],
),
)
TextSpan有点奇怪。text
参数是默认样式,但children
列表包含后面的样式文本(也可能是未样式文本)。如果要从带样式的文本开始,可以对text
使用空字符串。
您还可以添加TextDecorationStyle来更改装饰的外观。下面是虚线:
Text(
'Hello world',
style: TextStyle(
decoration: TextDecoration.underline,
decorationStyle: TextDecorationStyle.dashed,
),
)
和TextDecorationStyle.dotted
和TextDecorationStyle.double
和TextDecorationStyle.wavy
发布于 2018-05-31 07:31:09
您可以通过将decoration: TextDecoration.underline
应用于Text
的TextStyle
来完成此操作。
主题示例:
Text(
"text",
style: Theme
.of(context)
.accentTextTheme
.subhead
.copyWith(decoration: TextDecoration.underline),
)
基本示例:
Text(
"text",
style: TextStyle(decoration: TextDecoration.underline),
)
发布于 2020-05-06 23:50:54
例如
Text(
"Terms and Condition",
style: TextStyle(
decoration:
TextDecoration.underline,
height: 1.5,
fontSize: 15,
fontWeight: FontWeight.bold,
fontFamily: 'Roboto-Regular',
),
),
https://stackoverflow.com/questions/50614661
复制相似问题