How to make a line through text in Flutter?

FlutterDartText

Flutter Problem Overview


Using the TextStyle() class in Flutter, how can I strike through an old price?

Flutter Solutions


Solution 1 - Flutter

To apply strikethrough decoration to a Text widget directly:

Text('\$8.99', style: TextStyle(decoration: TextDecoration.lineThrough))

You can also style separate spans of a paragraph by using the RichText widget, or the Text.rich() constructor.

Based on this example code, to show a discounted price:

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',
      ),
    ],
 ),
)

Solution 2 - Flutter

          style: TextStyle(decoration: TextDecoration.lineThrough),

Solution 3 - Flutter

You can use it if you want to line color different

    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,
                ),
              ),
            )
          ],
        ))

Solution 4 - Flutter

i use this

Column(
    children: [
      Text(
        "sample text"
      ),
      Divider(color: Colors.red,)
    ],
  ),

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionOsama GamalView Question on Stackoverflow
Solution 1 - FlutterChance SnowView Answer on Stackoverflow
Solution 2 - FlutterTreeView Answer on Stackoverflow
Solution 3 - FlutterParesh MangukiyaView Answer on Stackoverflow
Solution 4 - Flutterzoha_shView Answer on Stackoverflow