Skip to content

Commit d95821c

Browse files
authored
fixed keyboardDismissBehavior on scroll without a drag (flutter#154675)
fixes flutter#154515, flutter#150048 and other similar issues where user non-draggable scrolls (mouse wheel, two-fingers) should behave same as draggable ones. In this PR, scrollUpdateNotification.dragDetails check is removed and it has a supporting test which simulates a scroll which does not produce a drag.
1 parent b4343c3 commit d95821c

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ class SingleChildScrollView extends StatelessWidget {
276276
child: scrollable,
277277
onNotification: (ScrollUpdateNotification notification) {
278278
final FocusScopeNode currentScope = FocusScope.of(context);
279-
if (notification.dragDetails != null && !currentScope.hasPrimaryFocus && currentScope.hasFocus) {
279+
if (!currentScope.hasPrimaryFocus && currentScope.hasFocus) {
280280
FocusManager.instance.primaryFocus?.unfocus();
281281
}
282282
return false;

packages/flutter/test/widgets/single_child_scroll_view_test.dart

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
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 'dart:ui';
6+
57
import 'package:flutter/material.dart';
68
import 'package:flutter/rendering.dart';
79
import 'package:flutter_test/flutter_test.dart';
@@ -1118,4 +1120,47 @@ void main() {
11181120

11191121
expect(tester.testTextInput.isVisible, isFalse);
11201122
});
1123+
1124+
testWidgets('keyboardDismissBehavior on scroll without a drag test', (WidgetTester tester) async {
1125+
await tester.pumpWidget(MaterialApp(
1126+
home: Scaffold(
1127+
body: SizedBox(
1128+
height: 1000,
1129+
child: SingleChildScrollView(
1130+
keyboardDismissBehavior: ScrollViewKeyboardDismissBehavior.onDrag,
1131+
child: Column(
1132+
children: <Widget>[
1133+
Autocomplete<String>(
1134+
optionsBuilder: (TextEditingValue textEditingValue) {
1135+
return<String>['aardvark', 'bobcat', 'chameleon']
1136+
.where((String option) {
1137+
return option.contains(textEditingValue.text.toLowerCase());
1138+
});
1139+
},
1140+
),
1141+
const SizedBox(height: 2000),
1142+
],
1143+
),
1144+
),
1145+
),
1146+
),
1147+
));
1148+
1149+
await tester.tap(find.byType(Autocomplete<String>));
1150+
await tester.pump();
1151+
1152+
await tester.enterText(find.byType(RawAutocomplete<String>),'aard');
1153+
await tester.pump();
1154+
1155+
expect(find.text('aardvark'), findsOneWidget);
1156+
1157+
final TestPointer testPointer = TestPointer(1, PointerDeviceKind.mouse);
1158+
final Offset scrollStart = tester.getCenter(find.byType(SingleChildScrollView));
1159+
1160+
testPointer.hover(scrollStart);
1161+
await tester.sendEventToBinding(testPointer.scroll(Offset(scrollStart.dx, scrollStart.dy - 100)));
1162+
await tester.pumpAndSettle();
1163+
1164+
expect(find.text('aardvark'), findsNothing);
1165+
});
11211166
}

0 commit comments

Comments
 (0)