将删除线装饰应用于Text
直接小部件:
Text('\$8.99', style: TextStyle(decoration: TextDecoration.lineThrough))
您还可以使用RichText https://docs.flutter.io/flutter/widgets/RichText-class.html小部件,或Text.rich() https://api.flutter.dev/flutter/widgets/Text/Text.rich.html构造函数。
基于这个示例代码 https://github.com/flutter/flutter/blob/09276bea258737e11b109e227f70eac94a4e1691/packages/flutter/lib/src/painting/text_style.dart#L106,显示折扣价:
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',
),
],
),
)