Revert "fixed keyboardDismissBehavior on scroll without a drag" (#161277)

Reverts https://github.com/flutter/flutter/pull/154675 as it regresses
`ScrollViewKeyboardDismissBehavior.onDrag`.

Fixes https://github.com/flutter/flutter/issues/160331
This commit is contained in:
Victor Sanni
2025-01-08 09:36:31 -08:00
committed by GitHub
parent 2b51318302
commit 9d7f6cc43b
2 changed files with 3 additions and 49 deletions

View File

@@ -276,7 +276,9 @@ class SingleChildScrollView extends StatelessWidget {
child: scrollable,
onNotification: (ScrollUpdateNotification notification) {
final FocusScopeNode currentScope = FocusScope.of(context);
if (!currentScope.hasPrimaryFocus && currentScope.hasFocus) {
if (notification.dragDetails != null &&
!currentScope.hasPrimaryFocus &&
currentScope.hasFocus) {
FocusManager.instance.primaryFocus?.unfocus();
}
return false;

View File

@@ -2,8 +2,6 @@
// 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';
@@ -1130,50 +1128,4 @@ 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);
});
}