LongPressGestureRecognizer constructor

  1. {Duration? duration,
  2. double? postAcceptSlopTolerance = null,
  3. Set<PointerDeviceKind>? supportedDevices,
  4. Object? debugOwner,
  5. AllowedButtonsFilter? allowedButtonsFilter}

Creates a long-press gesture recognizer.

Consider assigning the onLongPressStart callback after creating this object.

The postAcceptSlopTolerance argument can be used to specify a maximum allowed distance for the gesture to deviate from the starting point once the long press has triggered. If the gesture deviates past that point, subsequent callbacks (onLongPressMoveUpdate, onLongPressUp, onLongPressEnd) will stop. Defaults to null, which means the gesture can be moved without limit once the long press is accepted.

The duration argument can be used to overwrite the default duration after which the long press will be recognized.

The allowedButtonsFilter argument only gives this recognizer the ability to limit the buttons it accepts. It does not provide the ability to recognize any buttons beyond the ones it already accepts: kPrimaryButton, kSecondaryButton or kTertiaryButton. Therefore, a combined value of kPrimaryButton & kSecondaryButton would be ignored, but kPrimaryButton | kSecondaryButton would be allowed, as long as only one of them is selected at a time.

It's possible to limit this recognizer to a specific set of PointerDeviceKinds by providing the optional supportedDevices argument. If supportedDevices is null, the recognizer will accept pointer events from all device kinds.


  Duration? duration,
  super.postAcceptSlopTolerance = null,
  AllowedButtonsFilter? allowedButtonsFilter,
}) : super(
       deadline: duration ?? kLongPressTimeout,
       allowedButtonsFilter: allowedButtonsFilter ?? _defaultButtonAcceptBehavior,