From 9d7f6cc43bd1ba38b9c15f7fa6c3b1418a7b2720 Mon Sep 17 00:00:00 2001 From: Victor Sanni Date: Wed, 8 Jan 2025 09:36:31 -0800 Subject: [PATCH] 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 --- .../src/widgets/single_child_scroll_view.dart | 4 +- .../single_child_scroll_view_test.dart | 48 ------------------- 2 files changed, 3 insertions(+), 49 deletions(-) diff --git a/packages/flutter/lib/src/widgets/single_child_scroll_view.dart b/packages/flutter/lib/src/widgets/single_child_scroll_view.dart index c623cd4f45..a34611a9dd 100644 --- a/packages/flutter/lib/src/widgets/single_child_scroll_view.dart +++ b/packages/flutter/lib/src/widgets/single_child_scroll_view.dart @@ -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; diff --git a/packages/flutter/test/widgets/single_child_scroll_view_test.dart b/packages/flutter/test/widgets/single_child_scroll_view_test.dart index 7a0cb564dd..fe298f0b69 100644 --- a/packages/flutter/test/widgets/single_child_scroll_view_test.dart +++ b/packages/flutter/test/widgets/single_child_scroll_view_test.dart @@ -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: [ - Autocomplete( - optionsBuilder: (TextEditingValue textEditingValue) { - return ['aardvark', 'bobcat', 'chameleon'].where((String option) { - return option.contains(textEditingValue.text.toLowerCase()); - }); - }, - ), - const SizedBox(height: 2000), - ], - ), - ), - ), - ), - ), - ); - - await tester.tap(find.byType(Autocomplete)); - await tester.pump(); - - await tester.enterText(find.byType(RawAutocomplete), '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); - }); }