performLayout method

  1. @override
void performLayout()
override

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.

Implementation

@override
void performLayout() {
  final BoxConstraints constraints = this.constraints;
  _placeholderDimensions = layoutInlineChildren(constraints.maxWidth, ChildLayoutHelper.layoutChild, ChildLayoutHelper.getBaseline);
  _layoutTextWithConstraints(constraints);
  positionInlineChildren(_textPainter.inlinePlaceholderBoxes!);

  final Size textSize = _textPainter.size;
  size = constraints.constrain(textSize);

  final bool didOverflowHeight = size.height < textSize.height || _textPainter.didExceedMaxLines;
  final bool didOverflowWidth = size.width < textSize.width;
  // TODO(abarth): We're only measuring the sizes of the line boxes here. If
  // the glyphs draw outside the line boxes, we might think that there isn't
  // visual overflow when there actually is visual overflow. This can become
  // a problem if we start having horizontal overflow and introduce a clip
  // that affects the actual (but undetected) vertical overflow.
  final bool hasVisualOverflow = didOverflowWidth || didOverflowHeight;
  if (hasVisualOverflow) {
    switch (_overflow) {
      case TextOverflow.visible:
        _needsClipping = false;
        _overflowShader = null;
      case TextOverflow.clip:
      case TextOverflow.ellipsis:
        _needsClipping = true;
        _overflowShader = null;
      case TextOverflow.fade:
        _needsClipping = true;
        final TextPainter fadeSizePainter = TextPainter(
          text: TextSpan(style: _textPainter.text!.style, text: '\u2026'),
          textDirection: textDirection,
          textScaler: textScaler,
          locale: locale,
        )..layout();
        if (didOverflowWidth) {
          final (double fadeStart, double fadeEnd) = switch (textDirection) {
            TextDirection.rtl => (fadeSizePainter.width, 0.0),
            TextDirection.ltr => (size.width - fadeSizePainter.width, size.width),
          };
          _overflowShader = ui.Gradient.linear(
            Offset(fadeStart, 0.0),
            Offset(fadeEnd, 0.0),
            <Color>[const Color(0xFFFFFFFF), const Color(0x00FFFFFF)],
          );
        } else {
          final double fadeEnd = size.height;
          final double fadeStart = fadeEnd - fadeSizePainter.height / 2.0;
          _overflowShader = ui.Gradient.linear(
            Offset(0.0, fadeStart),
            Offset(0.0, fadeEnd),
            <Color>[const Color(0xFFFFFFFF), const Color(0x00FFFFFF)],
          );
        }
        fadeSizePainter.dispose();
    }
  } else {
    _needsClipping = false;
    _overflowShader = null;
  }
}