getConstraints method
Implementation
BoxConstraints getConstraints() {
if (enableWebFProfileTracking) {
WebFProfiler.instance.startTrackLayoutStep('RenderTextBox.getConstraints()');
}
if (renderStyle.whiteSpace == WhiteSpace.nowrap && renderStyle.effectiveTextOverflow != TextOverflow.ellipsis) {
if (enableWebFProfileTracking) {
WebFProfiler.instance.finishTrackLayoutStep();
}
return BoxConstraints();
}
double maxConstraintWidth = double.infinity;
if (parent is RenderBoxModel) {
RenderBoxModel parentRenderBoxModel = parent as RenderBoxModel;
BoxConstraints parentConstraints = parentRenderBoxModel.constraints;
if (parentRenderBoxModel.isScrollingContentBox && parentRenderBoxModel is! RenderFlexLayout) {
maxConstraintWidth = (parentRenderBoxModel.parent as RenderBoxModel).constraints.maxWidth;
} else if (parentConstraints.maxWidth == double.infinity) {
final ParentData? parentParentData = parentRenderBoxModel.parentData;
// Width of positioned element does not constrained by parent.
if (parentParentData is RenderLayoutParentData && parentParentData.isPositioned) {
maxConstraintWidth = double.infinity;
} else {
maxConstraintWidth = parentRenderBoxModel.renderStyle.contentMaxConstraintsWidth;
// @FIXME: Each character in the text will be placed in a new line when remaining space of
// parent is 0 cause word-break behavior can not be specified in flutter.
// https://github.com/flutter/flutter/issues/61081
// This behavior is not desirable compared to the default word-break:break-word value in the browser.
// So we choose to not do wrapping for text in this case.
if (maxConstraintWidth == 0) {
maxConstraintWidth = double.infinity;
}
}
} else {
EdgeInsets borderEdge = parentRenderBoxModel.renderStyle.border;
EdgeInsetsGeometry? padding = parentRenderBoxModel.renderStyle.padding;
double horizontalBorderLength = borderEdge.horizontal;
double horizontalPaddingLength = padding.horizontal;
maxConstraintWidth = parentConstraints.maxWidth - horizontalPaddingLength - horizontalBorderLength;
}
}
if (enableWebFProfileTracking) {
WebFProfiler.instance.finishTrackLayoutStep();
}
// Text will not overflow from container, so it can inherit
// constraints from parents
return BoxConstraints(minWidth: 0, maxWidth: maxConstraintWidth, minHeight: 0, maxHeight: double.infinity);
}