handleEvent method
- PointerEvent event
override
Called when a pointer event is routed to this recognizer.
This will be called for every pointer event while the pointer is being tracked. Typically, this recognizer will start tracking the pointer in addAllowedPointer, which means that handleEvent will be called starting with the PointerDownEvent that was passed to addAllowedPointer.
See also:
- startTrackingPointer, which causes pointer events to be routed to this recognizer.
- stopTrackingPointer, which stops events from being routed to this recognizer.
- stopTrackingIfPointerNoLongerDown, which conditionally stops events from being routed to this recognizer.
Implementation
@override
void handleEvent(PointerEvent event) {
if (event.pointer != _primaryPointer) {
return;
}
super.handleEvent(event);
if (event is PointerMoveEvent) {
// Receiving a [PointerMoveEvent], does not automatically mean the pointer
// being tracked is doing a drag gesture. There is some drift that can happen
// between the initial [PointerDownEvent] and subsequent [PointerMoveEvent]s.
// Accessing [_pastSlopTolerance] lets us know if our tap has moved past the
// acceptable tolerance. If the pointer does not move past this tolerance than
// it is not considered a drag.
//
// To be recognized as a drag, the [PointerMoveEvent] must also have moved
// a sufficient global distance from the initial [PointerDownEvent] to be
// accepted as a drag. This logic is handled in [_hasSufficientGlobalDistanceToAccept].
//
// The recognizer will also detect the gesture as a drag when the pointer
// has been accepted and it has moved past the [slopTolerance] but has not moved
// a sufficient global distance from the initial position to be considered a drag.
// In this case since the gesture cannot be a tap, it defaults to a drag.
final double computedSlop = computeHitSlop(event.kind, gestureSettings);
_pastSlopTolerance = _pastSlopTolerance || _getGlobalDistance(event, _initialPosition) > computedSlop;
if (_dragState == _DragState.accepted) {
_checkDragUpdate(event);
} else if (_dragState == _DragState.possible) {
if (_start == null) {
// Only check for a drag if the start of a drag was not already identified.
_checkDrag(event);
}
// This can occur when the recognizer is accepted before a [PointerMoveEvent] has been
// received that moves the pointer a sufficient global distance to be considered a drag.
if (_start != null && _wonArenaForPrimaryPointer) {
_dragState = _DragState.accepted;
_acceptDrag(_start!);
}
}
} else if (event is PointerUpEvent) {
if (_dragState == _DragState.possible) {
// The drag has not been accepted before a [PointerUpEvent], therefore the recognizer
// attempts to recognize a tap.
stopTrackingIfPointerNoLongerDown(event);
} else if (_dragState == _DragState.accepted) {
_giveUpPointer(event.pointer);
}
} else if (event is PointerCancelEvent) {
_dragState = _DragState.ready;
_giveUpPointer(event.pointer);
}
}