GestureDetector constructor

GestureDetector({
  1. Key? key,
  2. Widget? child,
  3. GestureTapDownCallback? onTapDown,
  4. GestureTapUpCallback? onTapUp,
  5. GestureTapCallback? onTap,
  6. GestureTapCancelCallback? onTapCancel,
  7. GestureTapCallback? onSecondaryTap,
  8. GestureTapDownCallback? onSecondaryTapDown,
  9. GestureTapUpCallback? onSecondaryTapUp,
  10. GestureTapCancelCallback? onSecondaryTapCancel,
  11. GestureTapDownCallback? onTertiaryTapDown,
  12. GestureTapUpCallback? onTertiaryTapUp,
  13. GestureTapCancelCallback? onTertiaryTapCancel,
  14. GestureTapDownCallback? onDoubleTapDown,
  15. GestureTapCallback? onDoubleTap,
  16. GestureTapCancelCallback? onDoubleTapCancel,
  17. GestureLongPressDownCallback? onLongPressDown,
  18. GestureLongPressCancelCallback? onLongPressCancel,
  19. GestureLongPressCallback? onLongPress,
  20. GestureLongPressStartCallback? onLongPressStart,
  21. GestureLongPressMoveUpdateCallback? onLongPressMoveUpdate,
  22. GestureLongPressUpCallback? onLongPressUp,
  23. GestureLongPressEndCallback? onLongPressEnd,
  24. GestureLongPressDownCallback? onSecondaryLongPressDown,
  25. GestureLongPressCancelCallback? onSecondaryLongPressCancel,
  26. GestureLongPressCallback? onSecondaryLongPress,
  27. GestureLongPressStartCallback? onSecondaryLongPressStart,
  28. GestureLongPressMoveUpdateCallback? onSecondaryLongPressMoveUpdate,
  29. GestureLongPressUpCallback? onSecondaryLongPressUp,
  30. GestureLongPressEndCallback? onSecondaryLongPressEnd,
  31. GestureLongPressDownCallback? onTertiaryLongPressDown,
  32. GestureLongPressCancelCallback? onTertiaryLongPressCancel,
  33. GestureLongPressCallback? onTertiaryLongPress,
  34. GestureLongPressStartCallback? onTertiaryLongPressStart,
  35. GestureLongPressMoveUpdateCallback? onTertiaryLongPressMoveUpdate,
  36. GestureLongPressUpCallback? onTertiaryLongPressUp,
  37. GestureLongPressEndCallback? onTertiaryLongPressEnd,
  38. GestureDragDownCallback? onVerticalDragDown,
  39. GestureDragStartCallback? onVerticalDragStart,
  40. GestureDragUpdateCallback? onVerticalDragUpdate,
  41. GestureDragEndCallback? onVerticalDragEnd,
  42. GestureDragCancelCallback? onVerticalDragCancel,
  43. GestureDragDownCallback? onHorizontalDragDown,
  44. GestureDragStartCallback? onHorizontalDragStart,
  45. GestureDragUpdateCallback? onHorizontalDragUpdate,
  46. GestureDragEndCallback? onHorizontalDragEnd,
  47. GestureDragCancelCallback? onHorizontalDragCancel,
  48. GestureForcePressStartCallback? onForcePressStart,
  49. GestureForcePressPeakCallback? onForcePressPeak,
  50. GestureForcePressUpdateCallback? onForcePressUpdate,
  51. GestureForcePressEndCallback? onForcePressEnd,
  52. GestureDragDownCallback? onPanDown,
  53. GestureDragStartCallback? onPanStart,
  54. GestureDragUpdateCallback? onPanUpdate,
  55. GestureDragEndCallback? onPanEnd,
  56. GestureDragCancelCallback? onPanCancel,
  57. GestureScaleStartCallback? onScaleStart,
  58. GestureScaleUpdateCallback? onScaleUpdate,
  59. GestureScaleEndCallback? onScaleEnd,
  60. HitTestBehavior? behavior,
  61. bool excludeFromSemantics = false,
  62. DragStartBehavior dragStartBehavior = DragStartBehavior.start,
  63. bool trackpadScrollCausesScale = false,
  64. Offset trackpadScrollToScaleFactor = kDefaultTrackpadScrollToScaleFactor,
  65. Set<PointerDeviceKind>? supportedDevices,
})

Creates a widget that detects gestures.

Pan and scale callbacks cannot be used simultaneously because scale is a superset of pan. Use the scale callbacks instead.

Horizontal and vertical drag callbacks cannot be used simultaneously because a combination of a horizontal and vertical drag is a pan. Use the pan callbacks instead.

By default, gesture detectors contribute semantic information to the tree that is used by assistive technology.

Implementation

GestureDetector({
  super.key,
  this.child,
  this.onTapDown,
  this.onTapUp,
  this.onTap,
  this.onTapCancel,
  this.onSecondaryTap,
  this.onSecondaryTapDown,
  this.onSecondaryTapUp,
  this.onSecondaryTapCancel,
  this.onTertiaryTapDown,
  this.onTertiaryTapUp,
  this.onTertiaryTapCancel,
  this.onDoubleTapDown,
  this.onDoubleTap,
  this.onDoubleTapCancel,
  this.onLongPressDown,
  this.onLongPressCancel,
  this.onLongPress,
  this.onLongPressStart,
  this.onLongPressMoveUpdate,
  this.onLongPressUp,
  this.onLongPressEnd,
  this.onSecondaryLongPressDown,
  this.onSecondaryLongPressCancel,
  this.onSecondaryLongPress,
  this.onSecondaryLongPressStart,
  this.onSecondaryLongPressMoveUpdate,
  this.onSecondaryLongPressUp,
  this.onSecondaryLongPressEnd,
  this.onTertiaryLongPressDown,
  this.onTertiaryLongPressCancel,
  this.onTertiaryLongPress,
  this.onTertiaryLongPressStart,
  this.onTertiaryLongPressMoveUpdate,
  this.onTertiaryLongPressUp,
  this.onTertiaryLongPressEnd,
  this.onVerticalDragDown,
  this.onVerticalDragStart,
  this.onVerticalDragUpdate,
  this.onVerticalDragEnd,
  this.onVerticalDragCancel,
  this.onHorizontalDragDown,
  this.onHorizontalDragStart,
  this.onHorizontalDragUpdate,
  this.onHorizontalDragEnd,
  this.onHorizontalDragCancel,
  this.onForcePressStart,
  this.onForcePressPeak,
  this.onForcePressUpdate,
  this.onForcePressEnd,
  this.onPanDown,
  this.onPanStart,
  this.onPanUpdate,
  this.onPanEnd,
  this.onPanCancel,
  this.onScaleStart,
  this.onScaleUpdate,
  this.onScaleEnd,
  this.behavior,
  this.excludeFromSemantics = false,
  this.dragStartBehavior = DragStartBehavior.start,
  this.trackpadScrollCausesScale = false,
  this.trackpadScrollToScaleFactor = kDefaultTrackpadScrollToScaleFactor,
  this.supportedDevices,
}) : assert(() {
       final bool haveVerticalDrag = onVerticalDragStart != null || onVerticalDragUpdate != null || onVerticalDragEnd != null;
       final bool haveHorizontalDrag = onHorizontalDragStart != null || onHorizontalDragUpdate != null || onHorizontalDragEnd != null;
       final bool havePan = onPanStart != null || onPanUpdate != null || onPanEnd != null;
       final bool haveScale = onScaleStart != null || onScaleUpdate != null || onScaleEnd != null;
       if (havePan || haveScale) {
         if (havePan && haveScale) {
           throw FlutterError.fromParts(<DiagnosticsNode>[
             ErrorSummary('Incorrect GestureDetector arguments.'),
             ErrorDescription(
               'Having both a pan gesture recognizer and a scale gesture recognizer is redundant; scale is a superset of pan.',
             ),
             ErrorHint('Just use the scale gesture recognizer.'),
           ]);
         }
         final String recognizer = havePan ? 'pan' : 'scale';
         if (haveVerticalDrag && haveHorizontalDrag) {
           throw FlutterError(
             'Incorrect GestureDetector arguments.\n'
             'Simultaneously having a vertical drag gesture recognizer, a horizontal drag gesture recognizer, and a $recognizer gesture recognizer '
             'will result in the $recognizer gesture recognizer being ignored, since the other two will catch all drags.',
           );
         }
       }
       return true;
     }());