layout method

void layout ({double minWidth: 0.0, double maxWidth: double.infinity })

Computes the visual position of the glyphs for painting the text.

The text will layout with a width that's as close to its max intrinsic width as possible while still being greater than or equal to minWidth and less than or equal to maxWidth.

The text and textDirection properties must be non-null before this is called.

Implementation

void layout({ double minWidth = 0.0, double maxWidth = double.infinity }) {
  assert(text != null, 'TextPainter.text must be set to a non-null value before using the TextPainter.');
  assert(textDirection != null, 'TextPainter.textDirection must be set to a non-null value before using the TextPainter.');
  if (!_needsLayout && minWidth == _lastMinWidth && maxWidth == _lastMaxWidth)
    return;
  _needsLayout = false;
  if (_paragraph == null) {
    final ui.ParagraphBuilder builder = ui.ParagraphBuilder(_createParagraphStyle());
    _text.build(builder, textScaleFactor: textScaleFactor);
    _paragraph = builder.build();
  }
  _lastMinWidth = minWidth;
  _lastMaxWidth = maxWidth;
  _paragraph.layout(ui.ParagraphConstraints(width: maxWidth));
  if (minWidth != maxWidth) {
    final double newWidth = maxIntrinsicWidth.clamp(minWidth, maxWidth);
    if (newWidth != width)
      _paragraph.layout(ui.ParagraphConstraints(width: newWidth));
  }
}