merge: 点击页面取消搜索焦点
This commit is contained in:
commit
cabc0e72f5
2 files changed
+52
No files matched your search
@@ -302,6 +302,7 @@ class _DiscoverPageState extends State<DiscoverPage> {
|
||||
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(
|
||||
|
||||
@@ -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<TextField>(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<TextField>(
|
||||
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 {
|
||||
|
||||
Reference in new issue
Block a user