startOrUpdateAutoScroll method
void
startOrUpdateAutoScroll({
- required AxisDirection direction,
- required double pointerDistance,
- double? maxToScroll,
Start or update a AutoScrollActivity
in the given AxisDirection
until maxToScroll
pixels have been scrolled with a velocity calculated
from the pointerDistance
.
If maxToScroll
is not specified it scrolls until it reaches the end of
the scrollable area.
Implementation
void startOrUpdateAutoScroll({
required AxisDirection direction,
required double pointerDistance,
double? maxToScroll,
}) {
final axis = axisDirectionToAxis(direction);
final controller = getScrollControllerFor(axis: axis)!;
final autoScrollController = getAutoScrollControllerFor(axis: axis);
final position = controller.position as ScrollPositionWithSingleContext;
if (autoScrollController != null) {
autoScrollController.pointerDistance = pointerDistance;
return;
}
GrowthDirection growthDirection;
if (direction == AxisDirection.right || direction == AxisDirection.down) {
growthDirection = GrowthDirection.forward;
} else {
growthDirection = GrowthDirection.reverse;
}
final newAutoScrollController = AutoScrollController(
pointerDistance: pointerDistance,
);
if (axis == Axis.vertical) {
verticalAutoScrollController = newAutoScrollController;
} else {
horizontalAutoScrollController = newAutoScrollController;
}
position.beginActivity(
AutoScrollActivity(
delegate: position,
position: position,
direction: growthDirection,
controller: newAutoScrollController,
maxToScroll: maxToScroll,
),
);
}