text property Null safety

InlineSpan? text

The (potentially styled) text to paint.

After this is set, you must call layout before the next call to paint. This and textDirection must be non-null before you call layout.

The InlineSpan this provides is in the form of a tree that may contain multiple instances of TextSpans and WidgetSpans. To obtain a plain text representation of the contents of this TextPainter, use InlineSpan.toPlainText to get the full contents of all nodes in the tree. TextSpan.text will only provide the contents of the first node in the tree.

Implementation

InlineSpan? get text => _text;
void text=(InlineSpan? value)

Implementation

set text(InlineSpan? value) {
  assert(value == null || value.debugAssertIsValid());
  if (_text == value)
    return;
  if (_text?.style != value?.style)
    _layoutTemplate = null;

  final RenderComparison comparison = value == null
    ? RenderComparison.layout
    : _text?.compareTo(value) ?? RenderComparison.layout;

  _text = value;

  if (comparison.index >= RenderComparison.layout.index) {
    markNeedsLayout();
  } else if (comparison.index >= RenderComparison.paint.index) {
    // Don't clear the _paragraph instance variable just yet. It still
    // contains valid layout information.
    _rebuildParagraphForPaint = true;
  }
  // Neither relayout or repaint is needed.
}