Flutter - Set Text line height
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 set or change the Text line height. In this example code, we will increase the Text line height instead of the default text line height.
Here we will assign a TextStyle instance for the Text widget’s style property. Then we will use the TextStyle class’s height property to set the line height for the Text widget's text.
The Text class’s style property value is a TextStyle object. The TextStyle class represents an immutable style describing how to format and paint text.
The TextStyle class’s height property value is a Double instance which is the height of this text span, as a multiple of the font size.
If the height property value is null or omitted, the line height will be determined by the font's metrics directly, which may differ from the font size. If the height is non-null, the line height of the span of text will be a multiple of the font size and be exactly font size * height logical pixels tall.
So finally, the flutter app developers can set or change the Text widget’s text line height using the TextStyle class height property.
The following flutter application development tutorial will demonstrate how we can set or change the Text line height. In this example code, we will increase the Text line height instead of the default text line height.
Here we will assign a TextStyle instance for the Text widget’s style property. Then we will use the TextStyle class’s height property to set the line height for the Text widget's text.
The Text class’s style property value is a TextStyle object. The TextStyle class represents an immutable style describing how to format and paint text.
The TextStyle class’s height property value is a Double instance which is the height of this text span, as a multiple of the font size.
If the height property value is null or omitted, the line height will be determined by the font's metrics directly, which may differ from the font size. If the height is non-null, the line height of the span of text will be a multiple of the font size and be exactly font size * height logical pixels tall.
So finally, the flutter app developers can set or change the Text widget’s text line height using the TextStyle class height property.
main.dart
import 'package:flutter/material.dart';
void main(){
runApp(
MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text("Flutter - Text line height")
),
body: const Center(
child: Text(
"Lorem Ipsum is simply dummy text of the printing"
" and typesetting industry.",
style: TextStyle(
fontSize: 24,
height: 2.5
),
textAlign: TextAlign.center,
),
),
),
)
);
}