Flutter - Text Line Through
The Text widget displays a string of text with a single style in a flutter
app. But depending on the layout constraints the string might break across
multiple lines or might all be displayed on the same line. The style argument
is optional in a Text instance. When the style argument is omitted, the text
will use the style from the closest enclosing DefaultTextStyle. By default,
the Text is not selectable. But flutter developers can make a Text selectable
by wrapping a subtree with a SelectionArea widget.
The following flutter application development tutorial will demonstrate how we can draw a line through the Text widget’s text. That means we will draw a line through each line of text. The developers also call it strikethrough text. Here we will assign a TextStyle instance for the Text widget’s style property.
In the below flutter example code, we will use the TextStyle class decoration property to decorate the Text widget’s text by drawing a line through each line.
The TextStyle class represents an immutable style describing how to format and paint text. The TextStyle class decoration property is used to apply decorations to paint near the text such as an overline. The flutter app developer can apply multiple decorations with TextDecoration.combine.
The TextDecoration class represents a linear decoration to draw near the text. The TextDecoration class’s lineThrough const draws a line through each line of text.
So finally, the flutter app developers can draw a line through each line of text inside a Text widget by using the TextStyle class’s decoration property. The flutter developers also have to set the decoration property value to the lineThrough constant as TextDecoration.lineThrough.
The following flutter application development tutorial will demonstrate how we can draw a line through the Text widget’s text. That means we will draw a line through each line of text. The developers also call it strikethrough text. Here we will assign a TextStyle instance for the Text widget’s style property.
In the below flutter example code, we will use the TextStyle class decoration property to decorate the Text widget’s text by drawing a line through each line.
The TextStyle class represents an immutable style describing how to format and paint text. The TextStyle class decoration property is used to apply decorations to paint near the text such as an overline. The flutter app developer can apply multiple decorations with TextDecoration.combine.
The TextDecoration class represents a linear decoration to draw near the text. The TextDecoration class’s lineThrough const draws a line through each line of text.
So finally, the flutter app developers can draw a line through each line of text inside a Text widget by using the TextStyle class’s decoration property. The flutter developers also have to set the decoration property value to the lineThrough constant as TextDecoration.lineThrough.
main.dart
import 'package:flutter/material.dart';
void main(){
runApp(
MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text("Flutter - Text line through")
),
body: const Center(
child: Text(
"Lorem Ipsum is simply dummy text of the printing"
" and typesetting industry.",
style: TextStyle(
decoration: TextDecoration.lineThrough,
decorationColor: Colors.red,
fontSize: 24,
),
textAlign: TextAlign.center,
),
),
),
)
);
}