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 of the current BuildContext to provide defaults.

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


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:



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

Get a 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


operator ==(other) bool

The equality operator.



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.

debugFillDescription(List<String> description) → void

Add additional information to the given description for use by toString.

mustCallSuper, protected, inherited
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.

toString() String

Returns a string representation of this object.

toStringShort() String

A short, textual description of this widget.