Skip to content

Commit d5e25f2

Browse files
authored
TextField in a ListView becomes unresponsive (#123734)
TextField in a ListView becomes unresponsive
1 parent daaba8a commit d5e25f2

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

packages/flutter/lib/src/widgets/tap_and_drag_gestures.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1218,7 +1218,9 @@ class TapAndDragGestureRecognizer extends OneSequenceGestureRecognizer with _Tap
12181218
keysPressedOnDown: keysPressedOnDown,
12191219
);
12201220

1221-
invokeCallback<void>('onDragEnd', () => onDragEnd!(endDetails));
1221+
if (onDragEnd != null) {
1222+
invokeCallback<void>('onDragEnd', () => onDragEnd!(endDetails));
1223+
}
12221224

12231225
_resetTaps();
12241226
_resetDragUpdateThrottle();

packages/flutter/test/widgets/tap_and_drag_gestures_test.dart

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
import 'package:flutter/foundation.dart';
56
import 'package:flutter/gestures.dart';
67
import 'package:flutter/widgets.dart';
78
import 'package:flutter_test/flutter_test.dart';
@@ -549,4 +550,42 @@ void main() {
549550
GestureBinding.instance.gestureArena.sweep(2);
550551
expect(events, <String>['down#1', 'up#1']);
551552
});
553+
554+
// This is a regression test for https://github.com/flutter/flutter/issues/102084.
555+
testGesture('Does not call onDragEnd if not provided', (GestureTester tester) {
556+
tapAndDrag = TapAndDragGestureRecognizer()
557+
..dragStartBehavior = DragStartBehavior.down
558+
..maxConsecutiveTap = 3
559+
..onTapDown = (TapDragDownDetails details) {
560+
events.add('down#${details.consecutiveTapCount}');
561+
};
562+
563+
FlutterErrorDetails? errorDetails;
564+
final FlutterExceptionHandler? oldHandler = FlutterError.onError;
565+
FlutterError.onError = (FlutterErrorDetails details) {
566+
errorDetails = details;
567+
};
568+
addTearDown(() {
569+
FlutterError.onError = oldHandler;
570+
});
571+
572+
tapAndDrag.addPointer(down5);
573+
tester.closeArena(5);
574+
tester.route(down5);
575+
tester.route(move5);
576+
tester.route(up5);
577+
GestureBinding.instance.gestureArena.sweep(5);
578+
expect(events, <String>['down#1']);
579+
580+
expect(errorDetails, isNull);
581+
582+
events.clear();
583+
tester.async.elapse(const Duration(milliseconds: 1000));
584+
tapAndDrag.addPointer(down1);
585+
tester.closeArena(1);
586+
tester.route(down1);
587+
tester.route(up1);
588+
GestureBinding.instance.gestureArena.sweep(1);
589+
expect(events, <String>['down#1']);
590+
});
552591
}

0 commit comments

Comments
 (0)