A paragraph of rich text.

The RichText widget displays text that uses multiple different styles. The text to display is described using a tree of TextSpan objects, each of which has an associated style that is used for that subtree. The text might break across multiple lines or might all be displayed on the same line depending on the layout constraints.

Text displayed in a RichText widget must be explicitly styled. When picking which style to use, consider using DefaultTextStyle.of the current BuildContext to provide defaults. For more details on how to style text in a RichText widget, see the documentation for TextStyle.

When all the text uses the same style, consider using the Text widget, which is less verbose and integrates with DefaultTextStyle for default styling.

Sample code

new RichText(
  text: new TextSpan(
    text: 'Hello ',
    style: DefaultTextStyle.of(context).style,
    children: <TextSpan>[
      new TextSpan(text: 'bold', style: new TextStyle(fontWeight: FontWeight.bold)),
      new TextSpan(text: ' world!'),

See also:

  • TextStyle, which discusses how to style text.
  • TextSpan, which is used to describe the text in a paragraph.
  • Text, which automatically applies the ambient styles described by a DefaultTextStyle to a single string.


RichText({Key key, @required TextSpan text, TextAlign textAlign, bool softWrap: true, TextOverflow overflow: TextOverflow.clip, double textScaleFactor: 1.0, int maxLines })
Creates a paragraph of rich text. [...]


maxLines int
An optional maximum number of lines for the text to span, wrapping if necessary. If the text exceeds the given number of lines, it will be truncated according to overflow. [...]
overflow TextOverflow
How visual overflow should be handled.
softWrap bool
Whether the text should break at soft line breaks. [...]
text TextSpan
The text to display in this widget.
textAlign TextAlign
How the text should be aligned horizontally.
textScaleFactor double
The number of font pixels for each logical pixel. [...]
hashCode int
The hash code for this object. [...]
read-only, inherited
key Key
Controls how one widget replaces another widget in the tree. [...]
final, inherited
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited


createRenderObject(BuildContext context) RenderParagraph
Creates an instance of the RenderObject class that this RenderObjectWidget represents, using the configuration described by this RenderObjectWidget. [...]
updateRenderObject(BuildContext context, RenderParagraph renderObject) → void
Copies the configuration described by this RenderObjectWidget to the given RenderObject, which will be of the same type as returned by this object's createRenderObject. [...]
createElement() LeafRenderObjectElement
RenderObjectWidgets always inflate to a RenderObjectElement subclass.
debugDescribeChildren() List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children. [...]
@protected, inherited
debugFillProperties(DiagnosticPropertiesBuilder description) → void
Add additional properties associated with the node. [...]
didUnmountRenderObject(RenderObject renderObject) → void
A render object previously associated with this widget has been removed from the tree. The given RenderObject will be of the same type as returned by this object's createRenderObject.
@protected, inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
toDiagnosticsNode({String name, DiagnosticsTreeStyle style }) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by toStringDeep. [...]
toString() String
Returns a string representation of this object.
toStringDeep([String prefixLineOne = '', String prefixOtherLines ]) String
Returns a string representation of this node and its descendants. [...]
toStringShallow([String joiner = ', ' ]) String
Returns a one-line detailed description of the object. [...]
toStringShort() String
A short, textual description of this widget.


operator ==(other) bool
The equality operator. [...]