gestureDetector for native gesture recognition. It supports tap, pan, and longPress.
drag is available as a pan alias when that better describes the interaction.
Tap
Pan with a shared value
mapEvent when the callback only copies event fields into shared values. Use event or a normal callback when custom logic is needed.
Long press
Gesture event data
Gesture events can includestate, x, y, absoluteX, absoluteY, translationX, translationY, velocityX, velocityY, pointerCount, and timestamp.
Lifecycle callbacks are onBegin, onStart, onUpdate, onEnd, onCancel, and onFinalize. onUpdate is continuous; use it sparingly and prefer mapEvent for direct animation updates.
Best practices
- Keep gesture callbacks small and move visual updates into shared values.
- Use
minDistanceto prevent accidental pans from taps. - Reset or settle shared values in
onEnd,onCancel, oronFinalize. - Do not perform network requests directly on every
onUpdateevent. - Test gestures on a real device because native touch arbitration affects final behavior.