handleThumbPressUpdate method

  1. @protected
  2. @mustCallSuper
void handleThumbPressUpdate(
  1. Offset localPosition
)

Handler called when a currently active long press gesture moves.

Updates the position of the child scrollable via the _drag ScrollDragController.

Implementation

@protected
@mustCallSuper
void handleThumbPressUpdate(Offset localPosition) {
  assert(_debugCheckHasValidScrollPosition());
  if (_lastDragUpdateOffset == localPosition) {
    return;
  }
  final ScrollPosition position = _cachedController!.position;
  if (!position.physics.shouldAcceptUserOffset(position)) {
    return;
  }
  final Axis? direction = getScrollbarDirection();
  if (direction == null) {
    return;
  }
  // _thumbDrag might be null if the drag activity ended and called _disposeThumbDrag.
  assert(_thumbHold == null || _thumbDrag == null);
  if (_thumbDrag == null) {
    return;
  }

  final double? primaryDelta = _getPrimaryDelta(localPosition);
  if (primaryDelta == null) {
    return;
  }

  final Offset delta = switch (direction) {
    Axis.horizontal => Offset(primaryDelta, 0),
    Axis.vertical => Offset(0, primaryDelta),
  };
  final RenderBox renderBox = _scrollbarPainterKey.currentContext!.findRenderObject()! as RenderBox;
  final DragUpdateDetails scrollDetails = DragUpdateDetails(
    delta: delta,
    primaryDelta: primaryDelta,
    globalPosition: renderBox.localToGlobal(localPosition),
    localPosition: localPosition,
  );
  _thumbDrag!.update(scrollDetails); // Triggers updates to the ScrollPosition and ScrollbarPainter

  _lastDragUpdateOffset = localPosition;
}