【发布时间】:2018-06-06 14:30:56
【问题描述】:
在 Flutter 中使用 TextStyle() 类,我如何才能突破旧价格?
【问题讨论】:
在 Flutter 中使用 TextStyle() 类,我如何才能突破旧价格?
【问题讨论】:
直接将删除线装饰应用于Text 小部件:
Text('\$8.99', style: TextStyle(decoration: TextDecoration.lineThrough))
您还可以使用RichText 小部件或Text.rich() 构造函数来设置段落的单独跨度。
基于this example code,显示折扣价:
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',
),
],
),
)
【讨论】:
Text(s, style: TextStyle(decoration: TextDecoration.lineThrough))
TextDecoration。
style: TextStyle(decoration: TextDecoration.lineThrough),
【讨论】:
如果你想用不同的线条颜色,你可以使用它
Container(
padding: EdgeInsets.all(20.0),
child: Stack(
children: <Widget>[
Text(
"Lorem Ipsum",
style: TextStyle(
fontSize: 20,
),
),
Container(
child: Text(
"Lorem Ipsum",
style: TextStyle(
color: Colors.transparent,
decorationColor: Colors.red,
decorationStyle: TextDecorationStyle.solid,
decoration:
TextDecoration.lineThrough,
fontSize: 20,
),
),
)
],
))
【讨论】:
我用这个
Column(
children: [
Text(
"sample text"
),
Divider(color: Colors.red,)
],
),
【讨论】: