layoutChildren method
void
layoutChildren(
- BoxConstraints constraints, {
- List<
int> ? hideWidgets, - TextPainter? textPainter,
- bool dry = false,
Implementation
void layoutChildren(
BoxConstraints constraints, {
List<int>? hideWidgets,
TextPainter? textPainter,
bool dry = false,
}) {
if (childCount == 0) {
return;
}
RenderBox? child = firstChild;
_placeholderDimensions = List<PlaceholderDimensions>.filled(
textChildCount, PlaceholderDimensions.empty,
growable: false);
// Only constrain the width to the maximum width of the paragraph.
// Leave height unconstrained, which will overflow if expanded past.
BoxConstraints boxConstraints =
BoxConstraints(maxWidth: constraints.maxWidth);
// The content will be enlarged by textScaleFactor during painting phase.
// We reduce constraints by textScaleFactor, so that the content will fit
// into the box once it is enlarged.
boxConstraints = boxConstraints / textScaleFactor;
int childIndex = 0;
while (child != null && childIndex < textChildCount) {
double? baselineOffset;
final Size childSize;
if (!dry) {
// Only constrain the width to the maximum width of the paragraph.
// Leave height unconstrained, which will overflow if expanded past.
child.layout(
hideWidgets != null && hideWidgets.contains(childIndex)
? const BoxConstraints(maxWidth: 0)
: boxConstraints,
parentUsesSize: true,
);
childSize = child.size;
switch (_placeholderSpans[childIndex].alignment) {
case ui.PlaceholderAlignment.baseline:
baselineOffset = child.getDistanceToBaseline(
_placeholderSpans[childIndex].baseline!,
);
break;
case ui.PlaceholderAlignment.aboveBaseline:
case ui.PlaceholderAlignment.belowBaseline:
case ui.PlaceholderAlignment.bottom:
case ui.PlaceholderAlignment.middle:
case ui.PlaceholderAlignment.top:
baselineOffset = null;
break;
}
} else {
assert(_placeholderSpans[childIndex].alignment !=
ui.PlaceholderAlignment.baseline);
childSize = child.getDryLayout(boxConstraints);
}
_placeholderDimensions![childIndex] = PlaceholderDimensions(
size: childSize,
alignment: _placeholderSpans[childIndex].alignment,
baseline: _placeholderSpans[childIndex].baseline,
baselineOffset: baselineOffset,
);
child = childAfter(child);
childIndex += 1;
}
(textPainter ?? this.textPainter)
.setPlaceholderDimensions(_placeholderDimensions);
}