childScrollOffset method
- covariant RenderObject child
override
Returns the scroll offset for the leading edge of the given child.
The child must be a child of this sliver.
If there are pinned slivers before child, the offset should be reduced
by the extent of the pinned children. This can occur in RenderSlivers
that have multiple sliver children, such as RenderSliverMainAxisGroup.
This method differs from childMainAxisPosition in that childMainAxisPosition gives the distance from the leading visible edge of the sliver whereas childScrollOffset gives the distance from sliver's zero scroll offset.
Implementation
@override
double? childScrollOffset(RenderObject child) {
assert(child.parent == this);
assert(child is RenderSliver);
final double extentOfPinnedSlivers = _maxScrollObstructionExtentBefore(child as RenderSliver);
final GrowthDirection growthDirection = constraints.growthDirection;
switch (growthDirection) {
case GrowthDirection.forward:
double childScrollOffset = 0.0;
RenderSliver? current = childBefore(child);
while (current != null) {
childScrollOffset += current.geometry!.scrollExtent;
current = childBefore(current);
}
return childScrollOffset - extentOfPinnedSlivers;
case GrowthDirection.reverse:
double childScrollOffset = 0.0;
RenderSliver? current = childAfter(child);
while (current != null) {
childScrollOffset -= current.geometry!.scrollExtent;
current = childAfter(current);
}
return childScrollOffset - extentOfPinnedSlivers;
}
}