Skip to content

Commit

Permalink
fix GestureDetector.onDoubleTapDown not getting called (#108056)
Browse files Browse the repository at this point in the history
  • Loading branch information
pedromassango authored Jul 22, 2022
1 parent 6898e09 commit 4fd27eb
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/flutter/lib/src/widgets/gesture_detector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1047,7 +1047,9 @@ class GestureDetector extends StatelessWidget {
);
}

if (onDoubleTap != null) {
if (onDoubleTap != null ||
onDoubleTapDown != null ||
onDoubleTapCancel != null) {
gestures[DoubleTapGestureRecognizer] = GestureRecognizerFactoryWithHandlers<DoubleTapGestureRecognizer>(
() => DoubleTapGestureRecognizer(debugOwner: this, supportedDevices: supportedDevices),
(DoubleTapGestureRecognizer instance) {
Expand Down
48 changes: 48 additions & 0 deletions packages/flutter/test/widgets/gesture_detector_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> log = <String>[];
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, <String>['double-tap']);
});

testWidgets('onDoubleTapDown is called even if onDoubleTap has not been not provided', (WidgetTester tester) async {
final List<String> log = <String>[];
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, <String>['double-tap-down']);
});
});
}

class _EmptySemanticsGestureDelegate extends SemanticsGestureDelegate {
Expand Down

0 comments on commit 4fd27eb

Please sign in to comment.