isHeightStretch property

  1. @override
bool get isHeightStretch
override

Implementation

@override
bool get isHeightStretch {
  RenderStyle renderStyle = this;
  if (renderStyle.parent == null) {
    return false;
  }
  bool isStretch = false;
  RenderStyle parentRenderStyle = renderStyle.parent!;

  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) {
    isStretch = true;
  }

  return isStretch;
}