onTouchEvent method
Implementation
bool onTouchEvent(PointerEvent event) {
var handle = false;
if (event is PointerDownEvent) {
// down
if (_gestureCallback.needHandle(GestureType.pressIn)) {
noPressIn = false;
_lastPressInX = event.position.dx;
_lastPressInY = event.position.dy;
_handler.sendDelayMessage(GestureType.pressIn, () {
_gestureCallback.handle(GestureType.pressIn, -1, -1);
});
handle = true;
} else {
noPressIn = true;
}
if (_gestureCallback.needHandle(GestureType.touchDown)) {
_gestureCallback.handle(
GestureType.touchDown,
event.position.dx,
event.position.dy,
);
handle = true;
}
if (!handle && _gestureCallback.needHandle(GestureType.touchMove)) {
handle = true;
}
if (!handle && _gestureCallback.needHandle(GestureType.touchEnd)) {
handle = true;
}
if (!handle && _gestureCallback.needHandle(GestureType.touchCancel)) {
handle = true;
}
} else if (event is PointerMoveEvent) {
// move
if (_gestureCallback.needHandle(GestureType.touchMove)) {
_gestureCallback.handle(
GestureType.touchMove,
event.position.dx,
event.position.dy,
);
handle = true;
}
if (!handle && _gestureCallback.needHandle(GestureType.touchEnd)) {
handle = true;
}
if (!handle && _gestureCallback.needHandle(GestureType.touchCancel)) {
handle = true;
}
if (!noPressIn) {
var distX = (event.position.dx - _lastPressInX).abs();
var distY = (event.position.dy - _lastPressInY).abs();
if (distX > kTouchSlop || distY > kTouchSlop) {
_handler.removeMessage(GestureType.pressIn);
noPressIn = true;
}
}
} else if (event is PointerUpEvent) {
// up
if (_gestureCallback.needHandle(GestureType.touchEnd)) {
_gestureCallback.handle(
GestureType.touchEnd,
event.position.dx,
event.position.dy,
);
handle = true;
}
if (noPressIn && _gestureCallback.needHandle(GestureType.pressOut)) {
_gestureCallback.handle(
GestureType.pressOut,
event.position.dx,
event.position.dy,
);
handle = true;
} else if (!noPressIn && _gestureCallback.needHandle(GestureType.pressOut)) {
_handler.sendDelayMessage(GestureType.pressOut, () {
_gestureCallback.handle(GestureType.pressOut, -1, -1);
});
handle = true;
}
} else if (event is PointerCancelEvent) {
// cancel
if (_gestureCallback.needHandle(GestureType.touchCancel)) {
_gestureCallback.handle(
GestureType.touchCancel,
event.position.dx,
event.position.dy,
);
handle = true;
}
if (noPressIn && _gestureCallback.needHandle(GestureType.pressOut)) {
_gestureCallback.handle(
GestureType.pressOut,
event.position.dx,
event.position.dy,
);
handle = true;
} else if (!noPressIn && _gestureCallback.needHandle(GestureType.pressOut)) {
_handler.removeMessage(GestureType.pressIn);
_handler.sendDelayMessage(GestureType.pressOut, () {
_gestureCallback.handle(GestureType.pressOut, -1, -1);
});
handle = true;
}
}
return handle;
}