scrollOffsetOf method

  1. @override
double scrollOffsetOf (RenderSliver child, double scrollOffsetWithinChild)
override

Returns the scroll offset within the viewport for the given scrollOffsetWithinChild within the given child.

The returned value is an estimate that assumes the slivers within the viewport do not change the layout extent in response to changes in their scroll offset.

Implementation

@override
double scrollOffsetOf(RenderSliver child, double scrollOffsetWithinChild) {
  assert(child.parent == this);
  final GrowthDirection growthDirection = child.constraints.growthDirection;
  assert(growthDirection != null);
  switch (growthDirection) {
    case GrowthDirection.forward:
      double scrollOffsetToChild = 0.0;
      RenderSliver current = center;
      while (current != child) {
        scrollOffsetToChild += current.geometry.scrollExtent;
        current = childAfter(current);
      }
      return scrollOffsetToChild + scrollOffsetWithinChild;
    case GrowthDirection.reverse:
      double scrollOffsetToChild = 0.0;
      RenderSliver current = childBefore(center);
      while (current != child) {
        scrollOffsetToChild -= current.geometry.scrollExtent;
        current = childBefore(current);
      }
      return scrollOffsetToChild - scrollOffsetWithinChild;
  }
  return null;
}