Simplify logic of TapGestureRecognizer (#30227)
Refactors the logic of TapGestureRecognizer, making the calling dependency unidirectional between resolve(accept) and checkUp.
diff --git a/packages/flutter/lib/src/gestures/tap.dart b/packages/flutter/lib/src/gestures/tap.dart
index 8212350..d567225 100644
--- a/packages/flutter/lib/src/gestures/tap.dart
+++ b/packages/flutter/lib/src/gestures/tap.dart
@@ -172,7 +172,10 @@
void handlePrimaryPointer(PointerEvent event) {
if (event is PointerUpEvent) {
_finalPosition = event.position;
- _checkUp();
+ if (_wonArenaForPrimaryPointer) {
+ resolve(GestureDisposition.accepted);
+ _checkUp();
+ }
} else if (event is PointerCancelEvent) {
if (_sentTapDown && onTapCancel != null) {
invokeCallback<void>('onTapCancel', onTapCancel);
@@ -230,16 +233,7 @@
}
void _checkUp() {
- if (_wonArenaForPrimaryPointer && _finalPosition != null) {
- resolve(GestureDisposition.accepted);
- if (!_wonArenaForPrimaryPointer || _finalPosition == null) {
- // It is possible that resolve has just recursively called _checkUp
- // (see https://github.com/flutter/flutter/issues/12470).
- // In that case _wonArenaForPrimaryPointer will be false (as _checkUp
- // calls _reset) and we return here to avoid double invocation of the
- // tap callbacks.
- return;
- }
+ if (_finalPosition != null) {
if (onTapUp != null)
invokeCallback<void>('onTapUp', () { onTapUp(TapUpDetails(globalPosition: _finalPosition)); });
if (onTap != null)