feat: search suggestion switch
This commit is contained in:
@ -25,6 +25,7 @@ class SSearchController extends GetxController {
|
||||
RxString defaultSearch = ''.obs;
|
||||
Box setting = GStrorage.setting;
|
||||
bool enableHotKey = true;
|
||||
bool enableSearchSuggest = true;
|
||||
late StreamController<bool> clearStream = StreamController<bool>.broadcast();
|
||||
|
||||
@override
|
||||
@ -47,6 +48,7 @@ class SSearchController extends GetxController {
|
||||
historyCacheList = GlobalDataCache().historyCacheList;
|
||||
historyList.value = historyCacheList;
|
||||
enableHotKey = setting.get(SettingBoxKey.enableHotKey, defaultValue: true);
|
||||
enableSearchSuggest = GlobalDataCache().enableSearchSuggest;
|
||||
}
|
||||
|
||||
void onChange(value) {
|
||||
@ -57,18 +59,16 @@ class SSearchController extends GetxController {
|
||||
return;
|
||||
}
|
||||
clearStream.add(true);
|
||||
_debouncer.call(() => querySearchSuggest(value));
|
||||
if (enableSearchSuggest) {
|
||||
_debouncer.call(() => querySearchSuggest(value));
|
||||
}
|
||||
}
|
||||
|
||||
void onClear() {
|
||||
if (searchKeyWord.value.isNotEmpty && controller.value.text != '') {
|
||||
controller.value.clear();
|
||||
searchKeyWord.value = '';
|
||||
searchSuggestList.value = [];
|
||||
clearStream.add(false);
|
||||
} else {
|
||||
Get.back();
|
||||
}
|
||||
controller.value.clear();
|
||||
searchKeyWord.value = '';
|
||||
searchSuggestList.value = [];
|
||||
clearStream.add(false);
|
||||
}
|
||||
|
||||
// 搜索
|
||||
|
@ -5,6 +5,7 @@ import 'package:hive/hive.dart';
|
||||
import 'package:pilipala/models/common/dynamics_type.dart';
|
||||
import 'package:pilipala/models/common/reply_sort_type.dart';
|
||||
import 'package:pilipala/pages/setting/widgets/select_dialog.dart';
|
||||
import 'package:pilipala/utils/global_data_cache.dart';
|
||||
import 'package:pilipala/utils/storage.dart';
|
||||
|
||||
import '../home/index.dart';
|
||||
@ -146,6 +147,15 @@ class _ExtraSettingState extends State<ExtraSetting> {
|
||||
setKey: SettingBoxKey.enableHotKey,
|
||||
defaultVal: true,
|
||||
),
|
||||
SetSwitchItem(
|
||||
title: '展示搜索建议',
|
||||
subTitle: '输入搜索内容时展示建议词',
|
||||
setKey: SettingBoxKey.enableSearchSuggest,
|
||||
defaultVal: true,
|
||||
callFn: (val) {
|
||||
GlobalDataCache().enableSearchSuggest = val;
|
||||
},
|
||||
),
|
||||
SetSwitchItem(
|
||||
title: '搜索默认词',
|
||||
subTitle: '是否展示搜索框默认词',
|
||||
|
@ -47,6 +47,8 @@ class GlobalDataCache {
|
||||
UserInfoData? userInfo;
|
||||
// 搜索历史
|
||||
late List historyCacheList;
|
||||
//
|
||||
late bool enableSearchSuggest = true;
|
||||
|
||||
// 私有构造函数
|
||||
GlobalDataCache._();
|
||||
@ -108,5 +110,7 @@ class GlobalDataCache {
|
||||
userInfo = userInfoCache.get('userInfoCache');
|
||||
sheetHeight = localCache.get('sheetHeight', defaultValue: 0.0);
|
||||
historyCacheList = localCache.get('cacheList', defaultValue: []);
|
||||
enableSearchSuggest =
|
||||
setting.get(SettingBoxKey.enableSearchSuggest, defaultValue: true);
|
||||
}
|
||||
}
|
||||
|
@ -107,6 +107,7 @@ class SettingBoxKey {
|
||||
replySortType = 'replySortType',
|
||||
defaultDynamicType = 'defaultDynamicType',
|
||||
enableHotKey = 'enableHotKey',
|
||||
enableSearchSuggest = 'enableSearchSuggest',
|
||||
enableQuickFav = 'enableQuickFav',
|
||||
enableWordRe = 'enableWordRe',
|
||||
enableSearchWord = 'enableSearchWord',
|
||||
|
Reference in New Issue
Block a user