TouchableOpacity constructor

TouchableOpacity(
  1. {Key? key,
  2. required Widget child,
  3. double activeOpacity = 0.2,
  4. GestureTapDownCallback? onTapDown,
  5. GestureTapUpCallback? onTapUp,
  6. GestureTapCallback? onTap,
  7. GestureTapCancelCallback? onTapCancel,
  8. GestureTapCallback? onDoubleTap,
  9. GestureLongPressCallback? onLongPress,
  10. GestureLongPressStartCallback? onLongPressStart,
  11. GestureLongPressMoveUpdateCallback? onLongPressMoveUpdate,
  12. GestureLongPressUpCallback? onLongPressUp,
  13. GestureLongPressEndCallback? onLongPressEnd,
  14. GestureDragDownCallback? onVerticalDragDown,
  15. GestureDragStartCallback? onVerticalDragStart,
  16. GestureDragUpdateCallback? onVerticalDragUpdate,
  17. GestureDragEndCallback? onVerticalDragEnd,
  18. GestureDragCancelCallback? onVerticalDragCancel,
  19. GestureDragDownCallback? onHorizontalDragDown,
  20. GestureDragStartCallback? onHorizontalDragStart,
  21. GestureDragUpdateCallback? onHorizontalDragUpdate,
  22. GestureDragEndCallback? onHorizontalDragEnd,
  23. GestureDragCancelCallback? onHorizontalDragCancel,
  24. GestureForcePressStartCallback? onForcePressStart,
  25. GestureForcePressPeakCallback? onForcePressPeak,
  26. GestureForcePressUpdateCallback? onForcePressUpdate,
  27. GestureForcePressEndCallback? onForcePressEnd,
  28. GestureDragDownCallback? onPanDown,
  29. GestureDragStartCallback? onPanStart,
  30. GestureDragUpdateCallback? onPanUpdate,
  31. GestureDragEndCallback? onPanEnd,
  32. GestureDragCancelCallback? onPanCancel,
  33. GestureScaleStartCallback? onScaleStart,
  34. GestureScaleUpdateCallback? onScaleUpdate,
  35. GestureScaleEndCallback? onScaleEnd,
  36. HitTestBehavior? behavior,
  37. bool excludeFromSemantics = false,
  38. DragStartBehavior dragStartBehavior = DragStartBehavior.start}
)

Creates a widget that uses Gesture Detector internally and works in the same way but fades the child when the user touches it.

By default the opacity of the child is animated to 0.2 when the user touches it, this can be changed by providing a value for activeOpacity

Pan and scale callbacks cannot be used simultaneously because scale is a superset of pan. Simply 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. Simply use the pan callbacks instead.

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

Implementation

TouchableOpacity({
  Key? key,
  required this.child,
  this.activeOpacity = 0.2,
  this.onTapDown,
  this.onTapUp,
  this.onTap,
  this.onTapCancel,
  this.onDoubleTap,
  this.onLongPress,
  this.onLongPressStart,
  this.onLongPressMoveUpdate,
  this.onLongPressUp,
  this.onLongPressEnd,
  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,
})  : assert(excludeFromSemantics != null),
      assert(dragStartBehavior != null),
      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('Incorrect TouchableOpacity arguments.\n'
                'Having both a pan gesture recognizer and a scale gesture recognizer is redundant; scale is a superset of pan. Just use the scale gesture recognizer.');
          }
          final String recognizer = havePan ? 'pan' : 'scale';
          if (haveVerticalDrag && haveHorizontalDrag) {
            throw FlutterError('Incorrect TouchableOpacity 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;
      }()),
      super(key: key);