semantics property

SemanticsGestureDelegate? semantics

Describes the semantics notations that should be added to the underlying render object RenderSemanticsGestureHandler.

It has no effect if excludeFromSemantics is true.

When semantics is null, RawGestureDetector will fall back to a default delegate which checks if the detector owns certain gesture recognizers and calls their callbacks if they exist:

This custom gesture detector listens to force presses, while also allows the same callback to be triggered by semantic long presses.
class ForcePressGestureDetectorWithSemantics extends StatelessWidget {
  const ForcePressGestureDetectorWithSemantics({
    required this.child,
    required this.onForcePress,

  final Widget child;
  final VoidCallback onForcePress;

  Widget build(BuildContext context) {
    return RawGestureDetector(
      gestures: <Type, GestureRecognizerFactory>{
        ForcePressGestureRecognizer: GestureRecognizerFactoryWithHandlers<ForcePressGestureRecognizer>(
          () => ForcePressGestureRecognizer(debugOwner: this),
          (ForcePressGestureRecognizer instance) {
            instance.onStart = (_) => onForcePress();
      behavior: HitTestBehavior.opaque,
      semantics: _LongPressSemanticsDelegate(onForcePress),
      child: child,

class _LongPressSemanticsDelegate extends SemanticsGestureDelegate {

  VoidCallback onLongPress;

  void assignSemantics(RenderSemanticsGestureHandler renderObject) {
    renderObject.onLongPress = onLongPress;


final SemanticsGestureDelegate? semantics;