The RichText
widget in Flutter is a widget for styling a paragraph of mixed-style text. It displays text that uses multiple different styles. Each text span in the paragraph can have a different style, such as font size, color, and font weight.
Here’s a basic example of using RichText
in Flutter:
RichText(
text: TextSpan(
style: DefaultTextStyle.of(context).style,
children: <TextSpan>[
TextSpan(text: 'Bold text: ', style: TextStyle(fontWeight: FontWeight.bold)),
TextSpan(text: 'Normal text'),
],
),
)
In this example, the first text span has a bold font weight, while the second text span has the default font weight.
Some of the properties that you can use with the RichText
widget include:
text
: The text to display in theRichText
widget. It’s specified as aTextSpan
object.textAlign
: The horizontal alignment of the text. The default value isTextAlign.start
.textDirection
: The direction of the text. The default value isTextDirection.ltr
.textScaleFactor
: The scaling factor for the text. The default value is 1.0.maxLines
: The maximum number of lines to display. If the text overflows, it will be truncated and an ellipsis will be displayed.softWrap
: Specifies whether the text should wrap. The default value istrue
.