calculateCacheOffset method

double calculateCacheOffset(
  1. SliverConstraints constraints,
  2. {required double from,
  3. required double to}
)

Computes the portion of the region from from to to that is within the cache extent of the viewport, assuming that only the region from the SliverConstraints.cacheOrigin that is SliverConstraints.remainingCacheExtent high is visible, and that the relationship between scroll offsets and paint offsets is linear.

This method is not useful if there is not a 1:1 relationship between consumed scroll offset and consumed cache extent.

Implementation

double calculateCacheOffset(SliverConstraints constraints, { required double from, required double to }) {
  assert(from <= to);
  final double a = constraints.scrollOffset + constraints.cacheOrigin;
  final double b = constraints.scrollOffset + constraints.remainingCacheExtent;
  // the clamp on the next line is to avoid floating point rounding errors
  return clampDouble(clampDouble(to, a, b) - clampDouble(from, a, b), 0.0, constraints.remainingCacheExtent);
}