From 4fd27eb6054bffe7c75e3108263f87946952bbb7 Mon Sep 17 00:00:00 2001 From: Pedro Massango Date: Fri, 22 Jul 2022 23:48:04 +0200 Subject: [PATCH] fix GestureDetector.onDoubleTapDown not getting called (#108056) --- .../lib/src/widgets/gesture_detector.dart | 4 +- .../test/widgets/gesture_detector_test.dart | 48 +++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/packages/flutter/lib/src/widgets/gesture_detector.dart b/packages/flutter/lib/src/widgets/gesture_detector.dart index 6ac0650832..bb859d8536 100644 --- a/packages/flutter/lib/src/widgets/gesture_detector.dart +++ b/packages/flutter/lib/src/widgets/gesture_detector.dart @@ -1047,7 +1047,9 @@ class GestureDetector extends StatelessWidget { ); } - if (onDoubleTap != null) { + if (onDoubleTap != null || + onDoubleTapDown != null || + onDoubleTapCancel != null) { gestures[DoubleTapGestureRecognizer] = GestureRecognizerFactoryWithHandlers( () => DoubleTapGestureRecognizer(debugOwner: this, supportedDevices: supportedDevices), (DoubleTapGestureRecognizer instance) { diff --git a/packages/flutter/test/widgets/gesture_detector_test.dart b/packages/flutter/test/widgets/gesture_detector_test.dart index 1463e24860..d82e7098f8 100644 --- a/packages/flutter/test/widgets/gesture_detector_test.dart +++ b/packages/flutter/test/widgets/gesture_detector_test.dart @@ -922,6 +922,54 @@ void main() { expect(panDelta, isNull); expect(didEndPan, isFalse); }); + + group('DoubleTap', () { + testWidgets('onDoubleTap is called even if onDoubleTapDown has not been not provided', (WidgetTester tester) async { + final List log = []; + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: GestureDetector( + onDoubleTap: () => log.add('double-tap'), + child: Container( + width: 100.0, + height: 100.0, + color: const Color(0xFF00FF00), + ), + ), + ), + ); + + await tester.tap(find.byType(Container)); + await tester.pump(kDoubleTapMinTime); + await tester.tap(find.byType(Container)); + await tester.pumpAndSettle(); + expect(log, ['double-tap']); + }); + + testWidgets('onDoubleTapDown is called even if onDoubleTap has not been not provided', (WidgetTester tester) async { + final List log = []; + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: GestureDetector( + onDoubleTapDown: (_) => log.add('double-tap-down'), + child: Container( + width: 100.0, + height: 100.0, + color: const Color(0xFF00FF00), + ), + ), + ), + ); + + await tester.tap(find.byType(Container)); + await tester.pump(kDoubleTapMinTime); + await tester.tap(find.byType(Container)); + await tester.pumpAndSettle(); + expect(log, ['double-tap-down']); + }); + }); } class _EmptySemanticsGestureDelegate extends SemanticsGestureDelegate {