From 41c40dfbc496eefd56c5c6f0522ecc4daa6fce47 Mon Sep 17 00:00:00 2001 From: guozhigq Date: Sun, 4 Feb 2024 00:26:20 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=83=AD=E6=90=9C=E8=AF=8D=E8=B7=B3?= =?UTF-8?q?=E8=BD=AC=E7=9B=B4=E6=92=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/models/search/hot.dart | 14 +++----------- lib/pages/search/controller.dart | 9 +++++++-- lib/pages/search/view.dart | 9 ++++----- lib/pages/search/widgets/hot_keyword.dart | 2 +- 4 files changed, 15 insertions(+), 19 deletions(-) diff --git a/lib/models/search/hot.dart b/lib/models/search/hot.dart index ce09b2ea..d2d77331 100644 --- a/lib/models/search/hot.dart +++ b/lib/models/search/hot.dart @@ -1,14 +1,8 @@ -import 'package:hive/hive.dart'; - -part 'hot.g.dart'; - -@HiveType(typeId: 6) class HotSearchModel { HotSearchModel({ this.list, }); - @HiveField(0) List? list; HotSearchModel.fromJson(Map json) { @@ -18,7 +12,6 @@ class HotSearchModel { } } -@HiveType(typeId: 7) class HotSearchItem { HotSearchItem({ this.keyword, @@ -27,20 +20,19 @@ class HotSearchItem { this.icon, }); - @HiveField(0) String? keyword; - @HiveField(1) String? showName; // 4/5热 11话题 8普通 7直播 - @HiveField(2) int? wordType; - @HiveField(3) String? icon; + List? liveId; HotSearchItem.fromJson(Map json) { keyword = json['keyword']; showName = json['show_name']; wordType = json['word_type']; icon = json['icon']; + liveId = json['live_id']; + liveId = json['live_id']; } } diff --git a/lib/pages/search/controller.dart b/lib/pages/search/controller.dart index 5ec1710a..d32da480 100644 --- a/lib/pages/search/controller.dart +++ b/lib/pages/search/controller.dart @@ -29,7 +29,7 @@ class SSearchController extends GetxController { // 其他页面跳转过来 if (Get.parameters.keys.isNotEmpty) { if (Get.parameters['keyword'] != null) { - onClickKeyword(Get.parameters['keyword']!); + onClickKeyword(Get.parameters['keyword']!, null); } if (Get.parameters['hintText'] != null) { hintText = Get.parameters['hintText']!; @@ -88,7 +88,12 @@ class SSearchController extends GetxController { } // 点击热搜关键词 - void onClickKeyword(String keyword) { + void onClickKeyword(String keyword, item) { + if (item != null && item.wordType == 7) { + Get.toNamed('/liveRoom?roomid=${item.liveId.first}', + arguments: {'liveItem': null, 'heroTag': '${item.liveId.first}'}); + return; + } searchKeyWord.value = keyword; controller.value.text = keyword; // 移动光标 diff --git a/lib/pages/search/view.dart b/lib/pages/search/view.dart index 252a8d63..e9fe0154 100644 --- a/lib/pages/search/view.dart +++ b/lib/pages/search/view.dart @@ -115,8 +115,8 @@ class _SearchPageState extends State with RouteAware { customBorder: RoundedRectangleBorder( borderRadius: BorderRadius.circular(4), ), - onTap: () => ssCtr - .onClickKeyword(ssCtr.searchSuggestList[index].term!), + onTap: () => ssCtr.onClickKeyword( + ssCtr.searchSuggestList[index].term!, null), child: Padding( padding: const EdgeInsets.only(left: 20, top: 9, bottom: 9), child: ssCtr.searchSuggestList[index].textRich, @@ -178,11 +178,11 @@ class _SearchPageState extends State with RouteAware { width: width, // ignore: invalid_use_of_protected_member hotSearchList: _searchController.hotSearchList.value, - onClick: (keyword) async { + onClick: (keyword, item) async { _searchController.searchFocusNode.unfocus(); await Future.delayed( const Duration(milliseconds: 150)); - _searchController.onClickKeyword(keyword); + _searchController.onClickKeyword(keyword, item); }, ), ); @@ -193,7 +193,6 @@ class _SearchPageState extends State with RouteAware { ); } } else { - // 缓存数据 return const SizedBox(); } }, diff --git a/lib/pages/search/widgets/hot_keyword.dart b/lib/pages/search/widgets/hot_keyword.dart index 66d01b1d..499e7ec5 100644 --- a/lib/pages/search/widgets/hot_keyword.dart +++ b/lib/pages/search/widgets/hot_keyword.dart @@ -26,7 +26,7 @@ class HotKeyword extends StatelessWidget { borderRadius: BorderRadius.circular(3), clipBehavior: Clip.hardEdge, child: InkWell( - onTap: () => onClick!(i.keyword), + onTap: () => onClick!(i.keyword, i), child: Padding( padding: EdgeInsets.only( left: 2,