Home > Mobile >  When does onTapCancel in GestureDetector gets called?
When does onTapCancel in GestureDetector gets called?

Time:12-05

We use GestureDetector's onTap every day, but when does onTapCancel gets called?

I read the implemention code, and noticed that onTapCancel comment:

  /// The pointer that previously triggered [onTapDown] will not end up causing
  /// a tap.
  ///
  /// This is called after [onTapDown], and instead of [onTapUp] and [onTap], if
  /// the tap gesture did not win.
  ///
  /// See also:
  ///
  ///  * [kPrimaryButton], the button this callback responds to.
  final GestureTapCancelCallback? onTapCancel;

Still can't figure out a scenary onTapCancel gets called, can anyone give me an example? Thanks in adavance :)

CodePudding user response:

It is typically called when the tap that caused onTapDown will not cause onTapUp. For instance, you press down on a GestureDetector, but then move your finger away from it, and let go.

CodePudding user response:

As far as I know, onTapCancel would be best suitable to use or call when you are using it in Dialog boxes like Alert, Info and etc. It will be useful to cancel the dialog box that is to make it pop and return the user to the previous page/state.

  • Related