handleThumbPressEnd method
Handler called when a long press has ended.
Implementation
@protected
@mustCallSuper
void handleThumbPressEnd(Offset localPosition, Velocity velocity) {
assert(_debugCheckHasValidScrollPosition());
final Axis? direction = getScrollbarDirection();
if (direction == null) {
return;
}
_maybeStartFadeoutTimer();
_cachedController = null;
_lastDragUpdateOffset = null;
// _thumbDrag might be null if the drag activity ended and called _disposeThumbDrag.
assert(_thumbHold == null || _thumbDrag == null);
if (_thumbDrag == null) {
return;
}
// On mobile platforms flinging the scrollbar thumb causes a ballistic
// scroll, just like it does via a touch drag. Likewise for desktops when
// dragging on the trackpad or with a stylus.
final TargetPlatform platform = ScrollConfiguration.of(context).getPlatform(context);
final Velocity adjustedVelocity = switch (platform) {
TargetPlatform.iOS || TargetPlatform.android => -velocity,
_ => Velocity.zero,
};
final RenderBox renderBox = _scrollbarPainterKey.currentContext!.findRenderObject()! as RenderBox;
final DragEndDetails details = DragEndDetails(
localPosition: localPosition,
globalPosition: renderBox.localToGlobal(localPosition),
velocity: adjustedVelocity,
primaryVelocity: switch (direction) {
Axis.horizontal => adjustedVelocity.pixelsPerSecond.dx,
Axis.vertical => adjustedVelocity.pixelsPerSecond.dy,
},
);
_thumbDrag?.end(details);
assert(_thumbDrag == null);
_startDragScrollbarAxisOffset = null;
_lastDragUpdateOffset = null;
_startDragThumbOffset = null;
_cachedController = null;
}