TextPainter class

An object that paints a TextSpan tree into a Canvas.

To use a TextPainter, follow these steps:

  1. Create a TextSpan tree and pass it to the TextPainter constructor.

  2. Call layout to prepare the paragraph.

  3. Call paint as often as desired to paint the paragraph.

If the width of the area into which the text is being painted changes, return to step 2. If the text to be painted changes, return to step 1.

The default text style is white. To change the color of the text, pass a TextStyle object to the TextSpan in text.

Constructors

TextPainter({TextSpan text, TextAlign textAlign: TextAlign.start, TextDirection textDirection, double textScaleFactor: 1.0, int maxLines, String ellipsis, Locale locale })
Creates a text painter that paints the given text. [...]

Properties

didExceedMaxLines bool
Whether any text was truncated or ellipsized. [...]
read-only
ellipsis String
The string used to ellipsize overflowing text. Setting this to a non-empty string will cause this string to be substituted for the remaining text if the text can not fit within the specified maximum width. [...]
read / write
height double
The vertical space required to paint this text. [...]
read-only
locale Locale
The locale used to select region-specific glyphs.
read / write
maxIntrinsicWidth double
The width at which increasing the width of the text no longer decreases the height. [...]
read-only
maxLines int
An optional maximum number of lines for the text to span, wrapping if necessary. [...]
read / write
minIntrinsicWidth double
The width at which decreasing the width of the text would prevent it from painting itself completely within its bounds. [...]
read-only
preferredLineHeight double
The height of a zero-width space in text in logical pixels. [...]
read-only
size Size
The amount of space required to paint this text. [...]
read-only
text TextSpan
The (potentially styled) text to paint. [...]
read / write
textAlign TextAlign
How the text should be aligned horizontally. [...]
read / write
textDirection TextDirection
The default directionality of the text. [...]
read / write
textScaleFactor double
The number of font pixels for each logical pixel. [...]
read / write
width double
The horizontal space required to paint this text. [...]
read-only
hashCode int
The hash code for this object. [...]
read-only, inherited
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited

Methods

computeDistanceToActualBaseline(TextBaseline baseline) double
Returns the distance from the top of the text to the first baseline of the given type. [...]
getBoxesForSelection(TextSelection selection) List<TextBox>
Returns a list of rects that bound the given selection. [...]
getOffsetAfter(int offset) int
Returns the closest offset after offset at which the inout cursor can be positioned.
getOffsetBefore(int offset) int
Returns the closest offset before offset at which the inout cursor can be positioned.
getOffsetForCaret(TextPosition position, Rect caretPrototype) Offset
Returns the offset at which to paint the caret. [...]
getPositionForOffset(Offset offset) TextPosition
Returns the position within the text for the given pixel offset.
getWordBoundary(TextPosition position) TextRange
Returns the text range of the word at the given offset. Characters not part of a word, such as spaces, symbols, and punctuation, have word breaks on both sides. In such cases, this method will return a text range that contains the given text position. [...]
layout({double minWidth: 0.0, double maxWidth: double.infinity }) → void
Computes the visual position of the glyphs for painting the text. [...]
paint(Canvas canvas, Offset offset) → void
Paints the text onto the given canvas at the given offset. [...]
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited
toString() String
Returns a string representation of this object.
inherited

Operators

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