findStickyChildren method

List<RenderBoxModel> findStickyChildren()

Find all the children whose position is sticky to this element

Implementation

List<RenderBoxModel> findStickyChildren() {
  List<RenderBoxModel> stickyChildren = [];

  RenderBox? child = firstChild;

  // Layout positioned element
  while (child != null) {
    final ContainerParentDataMixin<RenderBox>? childParentData =
        child.parentData as ContainerParentDataMixin<RenderBox>?;
    if (child is! RenderBoxModel) {
      child = childParentData!.nextSibling;
      continue;
    }

    RenderBoxModel childRenderBoxModel = child;
    RenderStyle childRenderStyle = childRenderBoxModel.renderStyle;
    CSSOverflowType overflowX = childRenderStyle.effectiveOverflowX;
    CSSOverflowType overflowY = childRenderStyle.effectiveOverflowY;

    if (CSSPositionedLayout.isSticky(childRenderBoxModel)) {
      stickyChildren.add(child);
    }

    // No need to loop scrollable container children
    if (overflowX != CSSOverflowType.visible ||
        overflowY != CSSOverflowType.visible) {
      child = childParentData!.nextSibling;
      continue;
    }
    if (child is RenderLayoutBox) {
      List<RenderBoxModel> mergedChildren = child.findStickyChildren();
      for (RenderBoxModel child in mergedChildren) {
        stickyChildren.add(child);
      }
    }
    child = childParentData!.nextSibling;
  }

  return stickyChildren;
}