使用 Flutter 中的TextStyle()
类,如何去除旧价格?
要将删除线修饰直接应用于Text
构件:
Text('$8.99', style: TextStyle(decoration: TextDecoration.lineThrough))
还可以使用RichText
构件或Text.rich()
构造函数设置段落的单独范围样式。
根据此示例代码,若要显示折扣价,请执行以下操作:
RichText()
new RichText(
text: new TextSpan(
text: 'This item costs ',
children: <TextSpan>[
new TextSpan(
text: '$8.99',
style: new TextStyle(
color: Colors.grey,
decoration: TextDecoration.lineThrough,
),
),
new TextSpan(
text: ' $3.99',
),
],
),
)
Text.rich()
Text.rich(TextSpan(
text: 'This item costs ',
children: <TextSpan>[
new TextSpan(
text: '$8.99',
style: new TextStyle(
color: Colors.grey,
decoration: TextDecoration.lineThrough,
),
),
new TextSpan(
text: ' $3.99',
),
],
),
)
style: TextStyle(decoration: TextDecoration.lineThrough),
我用这个
Column(
children: [
Text(
"sample text"
),
Divider(color: Colors.red,)
],
),