getVerticalDragScrollData function
Given the pointer local and global offsets return DragScrollData for the vertical axis.
Parameters:
displacementsee VirtualizationState.displacement.globalOffsetTheyoffset from the eventsglobalPosition.localOffsetTheyoffset from the eventslocalPosition.gestureOriginOffsetTheyoffset from the coordinate where the drag gesture started.viewportExtentThe total extent of the viewport in the vertical axis.screenHeightthe height of the screenfrozenExtentHow much of the viewport is dedicated to frozen headers.positionPixelthe current scrolled amount in the scroll viewscrollingDatasee 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();
}