maxScrollObstructionExtentBefore method Null safety

  1. @override
double maxScrollObstructionExtentBefore(
  1. RenderSliver child
)
override

Returns the total scroll obstruction extent of all slivers in the viewport before child.

This is the extent by which the actual area in which content can scroll is reduced. For example, an app bar that is pinned at the top will reduce the area in which content can actually scroll by the height of the app bar.

Implementation

@override
double maxScrollObstructionExtentBefore(RenderSliver child) {
  assert(child.parent == this);
  final GrowthDirection growthDirection = child.constraints.growthDirection;
  assert(growthDirection != null);
  switch (growthDirection) {
    case GrowthDirection.forward:
      double pinnedExtent = 0.0;
      RenderSliver? current = center;
      while (current != child) {
        pinnedExtent += current!.geometry!.maxScrollObstructionExtent;
        current = childAfter(current);
      }
      return pinnedExtent;
    case GrowthDirection.reverse:
      double pinnedExtent = 0.0;
      RenderSliver? current = childBefore(center!);
      while (current != child) {
        pinnedExtent += current!.geometry!.maxScrollObstructionExtent;
        current = childBefore(current);
      }
      return pinnedExtent;
  }
}