Implementation
@override
bool get isHeightStretch {
RenderStyle renderStyle = this;
CSSRenderStyle? parentRenderStyle = renderStyle.getAttachedRenderParentRenderStyle();
if (parentRenderStyle == null) {
return false;
}
// Stretching a flex item in the cross axis (height for row-direction flex)
// only applies when the flex container’s cross size is definite. A merely
// bounded (non-tight) maxHeight is not definite and must not force
// height:auto items to expand to the available extent (e.g., in Sliver/ListView).
final BoxConstraints? parentContentConstraints = parentRenderStyle.contentConstraints();
// Note: avoid calling parentRenderStyle.constraints() here. When computing
// styles for detached nodes (or before first layout), the parent may not
// have an attached render box and constraints() can be null/throw.
final bool parentHasDefiniteHeight =
parentRenderStyle.height.isNotAuto || (parentContentConstraints?.hasTightHeight ?? false);
bool isStretch = false;
bool isParentFlex =
parentRenderStyle.display == CSSDisplay.flex || parentRenderStyle.display == CSSDisplay.inlineFlex;
bool isHorizontalDirection = false;
bool isFlexNoWrap = false;
bool isChildStretchSelf = false;
if (isParentFlex) {
// The absolutely-positioned box is considered to be “fixed-size”, a value of stretch
// is treated the same as flex-start.
// https://www.w3.org/TR/css-flexbox-1/#abspos-items
bool isPositioned =
renderStyle.position == CSSPositionType.absolute || renderStyle.position == CSSPositionType.fixed;
if (isPositioned) {
return false;
}
isHorizontalDirection = CSSFlex.isHorizontalFlexDirection(parentRenderStyle.flexDirection);
isFlexNoWrap = parentRenderStyle.flexWrap != FlexWrap.wrap && parentRenderStyle.flexWrap != FlexWrap.wrapReverse;
isChildStretchSelf = renderStyle.alignSelf != AlignSelf.auto
? renderStyle.alignSelf == AlignSelf.stretch
: parentRenderStyle.alignItems == AlignItems.stretch;
}
CSSLengthValue marginTop = renderStyle.marginTop;
CSSLengthValue marginBottom = renderStyle.marginBottom;
// Display as block if flex vertical layout children and stretch children
if (marginTop.isNotAuto &&
marginBottom.isNotAuto &&
isParentFlex &&
isHorizontalDirection &&
isFlexNoWrap &&
isChildStretchSelf &&
parentHasDefiniteHeight) {
isStretch = true;
}
return isStretch;
}