handleEvent method
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) {
assert(_state != _SwipeState.ready);
if (!event.synthesized
&& (event is PointerDownEvent || event is PointerMoveEvent)) {
final VelocityTracker tracker = _velocityTrackers[event.pointer]!;
tracker.addPosition(event.timeStamp, event.localPosition);
}
if (event is PointerMoveEvent) {
if (event.buttons != _initialButtons) {
_giveUpPointer(event.pointer);
return;
}
_pendingDragOffset = _pendingDragOffset! + OffsetPair(local: event.localDelta, global: event.delta);
final Matrix4? localToGlobalTransform = event.transform == null ? null : Matrix4.tryInvert(event.transform!);
final Offset movedHorizontalLocally = Offset(event.localDelta.dx, 0.0);
_globalHorizontalDistanceMoved += PointerEvent.transformDeltaViaPositions(
transform: localToGlobalTransform,
untransformedDelta: movedHorizontalLocally,
untransformedEndPosition: event.localPosition,
).distance * (movedHorizontalLocally.dx).sign;
final Offset movedVerticalLocally = Offset(0.0, event.localDelta.dy);
_globalVerticalDistanceMoved += PointerEvent.transformDeltaViaPositions(
transform: localToGlobalTransform,
untransformedDelta: movedVerticalLocally,
untransformedEndPosition: event.localPosition,
).distance * (movedVerticalLocally.dy).sign;
if (_globalHorizontalDistanceMoved.abs() > _globalVerticalDistanceMoved.abs()) {
_direction = _globalHorizontalDistanceMoved > 0 ? DIRECTION_RIGHT : DIRECTION_LEFT;
} else {
_direction = _globalVerticalDistanceMoved > 0 ? DIRECTION_DOWN : DIRECTION_UP;
}
if (_state != _SwipeState.accepted && _hasSufficientGlobalDistanceToAccept(event.kind)) {
resolve(GestureDisposition.accepted);
}
}
if (event is PointerUpEvent || event is PointerCancelEvent) {
_giveUpPointer(
event.pointer,
reject: event is PointerCancelEvent || _state ==_SwipeState.possible,
);
}
}