performLayout method

  1. @override
void performLayout()

Do the work of computing the layout for this render object.

Do not call this function directly: call layout instead. This function is called by layout when there is actually work to be done by this render object during layout. The layout constraints provided by your parent are available via the constraints getter.

If sizedByParent is true, then this function should not actually change the dimensions of this render object. Instead, that work should be done by performResize. If sizedByParent is false, then this function should both change the dimensions of this render object and instruct its children to layout.

In implementing this function, you must call layout on each of your children, passing true for parentUsesSize if your layout information is dependent on your child's layout information. Passing true for parentUsesSize ensures that this render object will undergo layout if the child undergoes layout. Otherwise, the child can change its layout information without informing this render object.


void performLayout() {
  final BoxConstraints constraints = this.constraints;
  _placeholderDimensions = layoutInlineChildren(constraints.maxWidth, ChildLayoutHelper.layoutChild);
  final (double minWidth, double maxWidth) = _adjustConstraints(minWidth: constraints.minWidth, maxWidth: constraints.maxWidth);
    ..layout(minWidth: minWidth, maxWidth: maxWidth);
  // We grab _textPainter.size here because assigning to `size` on the next
  // line will trigger us to validate our intrinsic sizes, which will change
  // _textPainter's layout because the intrinsic size calculations are
  // destructive, which would mean we would get different results if we later
  // used properties on _textPainter in this method.
  // Other _textPainter state like didExceedMaxLines will also be affected,
  // though we currently don't use those here.
  // See also RenderParagraph which has a similar issue.
  final Size textPainterSize = _textPainter.size;
  final double width = forceLine
    ? constraints.maxWidth
    : constraints.constrainWidth(_textPainter.size.width + _caretMargin);
  assert(maxLines != 1 || _textPainter.maxLines == 1);
  final double preferredHeight = switch (maxLines) {
    null => math.max(_textPainter.height, preferredLineHeight * (minLines ?? 0)),
    1    => _textPainter.height,
    final int maxLines => clampDouble(
      preferredLineHeight * (minLines ?? maxLines),
      preferredLineHeight * maxLines,

  size = Size(width, constraints.constrainHeight(preferredHeight));
  final Size contentSize = Size(textPainterSize.width + _caretMargin, textPainterSize.height);

  final BoxConstraints painterConstraints = BoxConstraints.tight(contentSize);


  _maxScrollExtent = _getMaxScrollExtent(contentSize);
  offset.applyContentDimensions(0.0, _maxScrollExtent);