fix GestureDetector.onDoubleTapDown not getting called (#108056)

This commit is contained in:
Pedro Massango
2022-07-22 23:48:04 +02:00
committed by GitHub
parent 6898e09696
commit 4fd27eb605
2 changed files with 51 additions and 1 deletions

View File

@@ -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) {

View File

@@ -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 {