collapsedMarginBottomForSibling property

double get collapsedMarginBottomForSibling

Implementation

double get collapsedMarginBottomForSibling {
  // Start with own collapse-with-self result (empty-block handling), then
  // optionally fold in last-child collapse when eligible.
  RenderStyle? renderStyle = getSelfRenderStyle();
  if (renderStyle == null) return 0.0;

  double marginBottom = _collapsedMarginBottomWithSelf;

  double paddingBottom = renderStyle.paddingBottom.computedValue;
  double borderBottom = renderStyle.effectiveBorderBottomWidth.computedValue;
  bool isOverflowVisible = renderStyle.effectiveOverflowY == CSSOverflowType.visible;
  bool isOverflowClip = renderStyle.effectiveOverflowY == CSSOverflowType.clip;

  if (isLayoutBox() &&
      renderStyle.height.isAuto &&
      renderStyle.minHeight.isAuto &&
      renderStyle.maxHeight.isNone &&
      renderStyle.effectiveDisplay == CSSDisplay.block &&
      (isOverflowVisible || isOverflowClip) &&
      paddingBottom == 0 &&
      borderBottom == 0) {
    if (isLastChildAreRenderBoxModel() &&
        // Only collapse with the last in-flow block-level child. Ignore positioned children.
        isLastChildStyleMatch((rs) =>
            (rs.effectiveDisplay == CSSDisplay.block || rs.effectiveDisplay == CSSDisplay.flex) && !rs.isSelfPositioned())) {
      double childMarginBottom = isLastChildAreRenderLayoutBox()
          ? getLastChildRenderStyle<CSSMarginMixin>()!._collapsedMarginBottomWithLastChild
          : getLastChildRenderStyle<CSSMarginMixin>()!.marginBottom.computedValue;
      if (marginBottom < 0 && childMarginBottom < 0) {
        return math.min(marginBottom, childMarginBottom);
      } else if (marginBottom > 0 && childMarginBottom > 0) {
        return math.max(marginBottom, childMarginBottom);
      } else {
        return marginBottom + childMarginBottom;
      }
    }
  }

  return marginBottom;
}