From 199ddc0e7e04608ae271ec682a07c49d8da4c046 Mon Sep 17 00:00:00 2001 From: bggRGjQaUbCoE Date: Fri, 1 Aug 2025 21:06:28 +0800 Subject: [PATCH] fix disable search suggestion related #923 Signed-off-by: bggRGjQaUbCoE --- lib/pages/search/controller.dart | 18 +++++++------- lib/pages/search/view.dart | 40 ++++++++++++++++++-------------- lib/utils/storage_pref.dart | 2 +- 3 files changed, 32 insertions(+), 28 deletions(-) diff --git a/lib/pages/search/controller.dart b/lib/pages/search/controller.dart index 1e3ac5d2..5fde4cbd 100644 --- a/lib/pages/search/controller.dart +++ b/lib/pages/search/controller.dart @@ -39,8 +39,8 @@ class SSearchController extends GetxController { late final RxList searchSuggestList; // trending - final bool enableHotKey = Pref.enableHotKey; - late final Rx> loadingState; + final bool enableTrending = Pref.enableTrending; + late final Rx> trendingState; // rcmd final bool enableSearchRcmd = Pref.enableSearchRcmd; @@ -68,9 +68,9 @@ class SSearchController extends GetxController { searchSuggestList = [].obs; } - if (enableHotKey) { - loadingState = LoadingState.loading().obs; - queryHotSearchList(); + if (enableTrending) { + trendingState = LoadingState.loading().obs; + queryTrendingList(); } if (enableSearchRcmd) { @@ -97,7 +97,7 @@ class SSearchController extends GetxController { void onClear() { if (controller.value.text != '') { controller.clear(); - searchSuggestList.clear(); + if (searchSuggestion) searchSuggestList.clear(); searchFocusNode.requestFocus(); showUidBtn.value = false; } else { @@ -138,8 +138,8 @@ class SSearchController extends GetxController { } // 获取热搜关键词 - Future queryHotSearchList() async { - loadingState.value = await SearchHttp.searchTrending(limit: 10); + Future queryTrendingList() async { + trendingState.value = await SearchHttp.searchTrending(limit: 10); } Future queryRecommendList() async { @@ -150,7 +150,7 @@ class SSearchController extends GetxController { controller.text = keyword; validateUid(); - searchSuggestList.clear(); + if (searchSuggestion) searchSuggestList.clear(); submit(); } diff --git a/lib/pages/search/view.dart b/lib/pages/search/view.dart index 2dff5754..767a0d7e 100644 --- a/lib/pages/search/view.dart +++ b/lib/pages/search/view.dart @@ -80,21 +80,22 @@ class _SearchPageState extends State { children: [ if (_searchController.searchSuggestion) _searchSuggest(), if (isPortrait) ...[ - if (_searchController.enableHotKey) hotSearch(theme), + if (_searchController.enableTrending) hotSearch(theme), _history(theme, isPortrait), - if (_searchController.enableSearchRcmd) hotSearch(theme, false), + if (_searchController.enableSearchRcmd) + hotSearch(theme, isTrending: false), ] else Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ - if (_searchController.enableHotKey || + if (_searchController.enableTrending || _searchController.enableSearchRcmd) Expanded( child: Column( children: [ - if (_searchController.enableHotKey) hotSearch(theme), + if (_searchController.enableTrending) hotSearch(theme), if (_searchController.enableSearchRcmd) - hotSearch(theme, false), + hotSearch(theme, isTrending: false), ], ), ), @@ -155,9 +156,9 @@ class _SearchPageState extends State { ); } - Widget hotSearch(ThemeData theme, [bool isHot = true]) { + Widget hotSearch(ThemeData theme, {bool isTrending = true}) { final text = Text( - isHot ? '大家都在搜' : '搜索发现', + isTrending ? '大家都在搜' : '搜索发现', strutStyle: const StrutStyle(leading: 0, height: 1), style: theme.textTheme.titleMedium!.copyWith( height: 1, @@ -172,7 +173,7 @@ class _SearchPageState extends State { color: outline, ); return Padding( - padding: EdgeInsets.fromLTRB(10, isHot ? 25 : 4, 4, 25), + padding: EdgeInsets.fromLTRB(10, isTrending ? 25 : 4, 4, 25), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ @@ -181,7 +182,7 @@ class _SearchPageState extends State { child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - isHot + isTrending ? Row( mainAxisSize: MainAxisSize.min, children: [ @@ -224,8 +225,8 @@ class _SearchPageState extends State { EdgeInsets.symmetric(horizontal: 10, vertical: 6), ), ), - onPressed: isHot - ? _searchController.queryHotSearchList + onPressed: isTrending + ? _searchController.queryTrendingList : _searchController.queryRecommendList, icon: Icon( Icons.refresh_outlined, @@ -247,10 +248,10 @@ class _SearchPageState extends State { ), Obx( () => _buildHotKey( - isHot - ? _searchController.loadingState.value + isTrending + ? _searchController.trendingState.value : _searchController.recommendData.value, - isHot, + isTrending, ), ), ], @@ -270,7 +271,7 @@ class _SearchPageState extends State { 10, !isPortrait ? 25 - : _searchController.enableHotKey + : _searchController.enableTrending ? 0 : 6, 6, @@ -375,7 +376,10 @@ class _SearchPageState extends State { color: theme.colorScheme.onSurfaceVariant.withValues(alpha: 0.8), ); - Widget _buildHotKey(LoadingState loadingState, bool isHot) { + Widget _buildHotKey( + LoadingState loadingState, + bool isTrending, + ) { return switch (loadingState) { Success(:var response) => response.list?.isNotEmpty == true @@ -389,8 +393,8 @@ class _SearchPageState extends State { : const SizedBox.shrink(), Error(:var errMsg) => errorWidget( errMsg: errMsg, - onReload: isHot - ? _searchController.queryHotSearchList + onReload: isTrending + ? _searchController.queryTrendingList : _searchController.queryRecommendList, ), _ => const SizedBox.shrink(), diff --git a/lib/utils/storage_pref.dart b/lib/utils/storage_pref.dart index 60149b13..ed2167a7 100644 --- a/lib/utils/storage_pref.dart +++ b/lib/utils/storage_pref.dart @@ -742,7 +742,7 @@ class Pref { static bool get defaultShowComment => _setting.get(SettingBoxKey.defaultShowComment, defaultValue: false); - static bool get enableHotKey => + static bool get enableTrending => _setting.get(SettingBoxKey.enableHotKey, defaultValue: true); static bool get enableSearchRcmd =>