getVerticalDragScrollData function

DragScrollData getVerticalDragScrollData({
  1. required double displacement,
  2. required double globalOffset,
  3. required double localOffset,
  4. required double gestureOriginOffset,
  5. required double viewportExtent,
  6. required double screenHeight,
  7. required double frozenExtent,
  8. required double positionPixel,
  9. required ScrollingData scrollingData,
})

Given the pointer local and global offsets return DragScrollData for the vertical axis.

Parameters:

  • displacement see VirtualizationState.displacement.
  • globalOffset The y offset from the events globalPosition.
  • localOffset The y offset from the events localPosition.
  • gestureOriginOffset The y offset from the coordinate where the drag gesture started.
  • viewportExtent The total extent of the viewport in the vertical axis.
  • screenHeight the height of the screen
  • frozenExtent How much of the viewport is dedicated to frozen headers.
  • positionPixel the current scrolled amount in the scroll view
  • scrollingData see VirtualizationState.scrollingData

Implementation

DragScrollData getVerticalDragScrollData({
  required double displacement,
  required double globalOffset,
  required double localOffset,
  required double gestureOriginOffset,
  required double viewportExtent,
  required double screenHeight,
  required double frozenExtent,
  required double positionPixel,
  required ScrollingData scrollingData,
}) {
  // The point that represents the top edge of the scrollable part.
  final topThreshold = displacement.abs() + frozenExtent;
  if (gestureOriginOffset < topThreshold) {
    // If the gesture started in a frozen pane
    if (localOffset >= topThreshold) {
      // Going to the scrollable area should reset scroll
      return ResetScrollDragScrollData();
    }
    // Keeping the drag in the frozen area should not scroll
    return DoNotScrollDragScrollData();
  }

  final precedingScrollExtent = scrollingData.constraints.precedingScrollExtent;

  final pointerDistanceToTopThreshold = topThreshold - localOffset;
  if (pointerDistanceToTopThreshold > 0) {
    return AutoScrollDragScrollData(
      direction: AxisDirection.up,
      maxToScroll: positionPixel - precedingScrollExtent + displacement.abs(),
      pointerDistance: pointerDistanceToTopThreshold,
    );
  }

  final bottomThreshold = screenHeight - kAutoScrollTriggerThreshold;
  final pointerDistanceToBottomThreshold = globalOffset - bottomThreshold;
  if (pointerDistanceToBottomThreshold > 0) {
    // The bottom of the table is the amount scrolled on previous slivers
    // plus the total extent of the table (which includes headers and top
    // padding).
    final tableBottomPixel = precedingScrollExtent + scrollingData.totalExtent;

    // The current bottom of the table is the which is the amount of pixels
    // already scrolled plus the leadingPadding (header + top padding) and
    // the current viewport extent.
    final viewportTableBottom = positionPixel + viewportExtent + scrollingData.leadingPadding;
    return AutoScrollDragScrollData(
      direction: AxisDirection.down,
      maxToScroll: tableBottomPixel - viewportTableBottom + config.kColumnHeaderHeight,
      pointerDistance: pointerDistanceToBottomThreshold,
    );
  }

  return DoNotScrollDragScrollData();
}