fixed keyboardDismissBehavior on scroll without a drag (#154675)
fixes #154515, #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.
This commit is contained in:
parent
b4343c316a
commit
d95821c1d1
@ -276,7 +276,7 @@ class SingleChildScrollView extends StatelessWidget {
|
||||
child: scrollable,
|
||||
onNotification: (ScrollUpdateNotification notification) {
|
||||
final FocusScopeNode currentScope = FocusScope.of(context);
|
||||
if (notification.dragDetails != null && !currentScope.hasPrimaryFocus && currentScope.hasFocus) {
|
||||
if (!currentScope.hasPrimaryFocus && currentScope.hasFocus) {
|
||||
FocusManager.instance.primaryFocus?.unfocus();
|
||||
}
|
||||
return false;
|
||||
|
@ -2,6 +2,8 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
@ -1118,4 +1120,47 @@ void main() {
|
||||
|
||||
expect(tester.testTextInput.isVisible, isFalse);
|
||||
});
|
||||
|
||||
testWidgets('keyboardDismissBehavior on scroll without a drag test', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(MaterialApp(
|
||||
home: Scaffold(
|
||||
body: SizedBox(
|
||||
height: 1000,
|
||||
child: SingleChildScrollView(
|
||||
keyboardDismissBehavior: ScrollViewKeyboardDismissBehavior.onDrag,
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
Autocomplete<String>(
|
||||
optionsBuilder: (TextEditingValue textEditingValue) {
|
||||
return<String>['aardvark', 'bobcat', 'chameleon']
|
||||
.where((String option) {
|
||||
return option.contains(textEditingValue.text.toLowerCase());
|
||||
});
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 2000),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
));
|
||||
|
||||
await tester.tap(find.byType(Autocomplete<String>));
|
||||
await tester.pump();
|
||||
|
||||
await tester.enterText(find.byType(RawAutocomplete<String>),'aard');
|
||||
await tester.pump();
|
||||
|
||||
expect(find.text('aardvark'), findsOneWidget);
|
||||
|
||||
final TestPointer testPointer = TestPointer(1, PointerDeviceKind.mouse);
|
||||
final Offset scrollStart = tester.getCenter(find.byType(SingleChildScrollView));
|
||||
|
||||
testPointer.hover(scrollStart);
|
||||
await tester.sendEventToBinding(testPointer.scroll(Offset(scrollStart.dx, scrollStart.dy - 100)));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('aardvark'), findsNothing);
|
||||
});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user