applyStickyChildOffset static method
Implementation
static void applyStickyChildOffset(RenderBoxModel scrollContainer, RenderBoxModel child) {
RenderPositionPlaceholder childRenderPositionHolder = child.renderPositionPlaceholder!;
RenderLayoutParentData childPlaceHolderParentData = childRenderPositionHolder.parentData as RenderLayoutParentData;
// Original offset of sticky child in relative status
Offset childOriginalOffset = childPlaceHolderParentData.offset;
// Offset of sticky child to scroll container
Offset childToScrollContainerOffset =
childRenderPositionHolder.localToGlobal(Offset.zero, ancestor: scrollContainer);
bool isVerticalFixed = false;
bool isHorizontalFixed = false;
RenderStyle childRenderStyle = child.renderStyle;
if (childRenderStyle.left.isNotAuto || childRenderStyle.right.isNotAuto) {
isHorizontalFixed =
_applyStickyChildHorizontalOffset(scrollContainer, child, childOriginalOffset, childToScrollContainerOffset);
}
if (childRenderStyle.top.isNotAuto || childRenderStyle.bottom.isNotAuto) {
isVerticalFixed =
_applyStickyChildVerticalOffset(scrollContainer, child, childOriginalOffset, childToScrollContainerOffset);
}
if (isVerticalFixed || isHorizontalFixed) {
// Change sticky status to fixed
child.stickyStatus = StickyPositionType.fixed;
child.markNeedsPaint();
} else {
// Change sticky status to relative
if (child.stickyStatus == StickyPositionType.fixed) {
child.stickyStatus = StickyPositionType.relative;
// Reset child offset to its original offset
child.markNeedsPaint();
}
}
}