From 884687d10a7b05492eb50a0fb18c9a7d3f9ad4cd Mon Sep 17 00:00:00 2001 From: Zhou Weidong <502333560@qq.com> Date: Mon, 19 Oct 2026 18:04:00 +0800 Subject: [PATCH] =?UTF-8?q?fix(discover):=20=E7=82=B9=E5=87=BB=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E5=8F=96=E6=B6=88=E6=90=9C=E7=B4=A2=E7=84=A6=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/pages/discover/discover_view.dart | 1 + test/discover/home_all_dramas_grid_test.dart | 51 ++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/lib/pages/discover/discover_view.dart b/lib/pages/discover/discover_view.dart index 1db6c8a..a520c43 100644 --- a/lib/pages/discover/discover_view.dart +++ b/lib/pages/discover/discover_view.dart @@ -302,6 +302,7 @@ class _DiscoverPageState extends State { controller: logic.search, focusNode: logic.searchFocus, onChanged: (_) => logic.onSearchChanged(), + onTapOutside: (_) => logic.searchFocus.unfocus(), textInputAction: TextInputAction.search, style: const TextStyle(color: AppColors.onSurface, fontSize: 13), decoration: InputDecoration( diff --git a/test/discover/home_all_dramas_grid_test.dart b/test/discover/home_all_dramas_grid_test.dart index 419b6b0..b7aad49 100644 --- a/test/discover/home_all_dramas_grid_test.dart +++ b/test/discover/home_all_dramas_grid_test.dart @@ -295,6 +295,57 @@ void main() { ); }); + testWidgets('should_unfocus_search_without_losing_input_or_filter', ( + tester, + ) async { + tester.view.physicalSize = const Size(390, 844); + tester.view.devicePixelRatio = 1; + addTearDown(tester.view.resetPhysicalSize); + addTearDown(tester.view.resetDevicePixelRatio); + + await _pumpApp(tester, categoryRepository: _GridCategoryRepository()); + await tester.tap(find.byKey(const Key('tab-discover'))); + await tester.pumpAndSettle(); + + await tester.tap(find.byKey(const Key('discover-search'))); + await tester.pump(); + expect( + tester + .widget(find.byKey(const Key('discover-search'))) + .focusNode! + .hasFocus, + isTrue, + ); + + await tester.enterText(find.byKey(const Key('discover-search')), 'velvet'); + await tester.pumpAndSettle(); + expect( + find.byKey(const Key('home-drama-card-city-lights-demo')), + findsOneWidget, + ); + expect( + find.byKey(const Key('home-drama-card-the-signal-demo')), + findsNothing, + ); + + await tester.tapAt(const Offset(70, 23)); + await tester.pump(); + + final field = tester.widget( + find.byKey(const Key('discover-search')), + ); + expect(field.focusNode!.hasFocus, isFalse); + expect(field.controller!.text, 'velvet'); + expect( + find.byKey(const Key('home-drama-card-city-lights-demo')), + findsOneWidget, + ); + expect( + find.byKey(const Key('home-drama-card-the-signal-demo')), + findsNothing, + ); + }); + testWidgets('should_show_continue_watching_only_when_a_record_exists', ( tester, ) async {