contentMaxConstraintsWidth property
double
get
contentMaxConstraintsWidth
override
Implementation
@override
double get contentMaxConstraintsWidth {
// If renderBoxModel definite content constraints, use it as max constrains width of content.
BoxConstraints? contentConstraints = renderBoxModel!.contentConstraints;
if (contentConstraints != null && contentConstraints.maxWidth != double.infinity) {
return contentConstraints.maxWidth;
}
double contentMaxConstraintsWidth = double.infinity;
RenderStyle renderStyle = this;
double? borderBoxLogicalWidth;
RenderStyle? ancestorRenderStyle = _findAncestorWithContentBoxLogicalWidth();
// If renderBoxModel has no logical width (eg. display is inline-block/inline-flex and
// has no width), the child width is constrained by its closest ancestor who has definite logical content box width.
if (ancestorRenderStyle != null) {
borderBoxLogicalWidth = ancestorRenderStyle.contentBoxLogicalWidth;
}
if (borderBoxLogicalWidth != null) {
contentMaxConstraintsWidth = borderBoxLogicalWidth -
renderStyle.border.horizontal -
renderStyle.padding.horizontal;
// Logical width may be smaller than its border and padding width,
// in this case, content width will be negative which is illegal.
// <div style="width: 300px;">
// <div style="display: inline-block; padding: 0 200px;">
// </div>
// </div>
contentMaxConstraintsWidth = math.max(0, contentMaxConstraintsWidth);
}
return contentMaxConstraintsWidth;
}