feat: search user by uid
This commit is contained in:
@ -26,7 +26,6 @@ class SSearchController extends GetxController {
|
||||
Box setting = GStrorage.setting;
|
||||
bool enableHotKey = true;
|
||||
bool enableSearchSuggest = true;
|
||||
late StreamController<bool> clearStream = StreamController<bool>.broadcast();
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
@ -42,7 +41,6 @@ class SSearchController extends GetxController {
|
||||
final hint = parameters['hintText'];
|
||||
if (hint != null) {
|
||||
hintText = hint;
|
||||
searchKeyWord.value = hintText;
|
||||
}
|
||||
}
|
||||
historyCacheList = GlobalDataCache().historyCacheList;
|
||||
@ -55,10 +53,8 @@ class SSearchController extends GetxController {
|
||||
searchKeyWord.value = value;
|
||||
if (value == '') {
|
||||
searchSuggestList.value = [];
|
||||
clearStream.add(false);
|
||||
return;
|
||||
}
|
||||
clearStream.add(true);
|
||||
if (enableSearchSuggest) {
|
||||
_debouncer.call(() => querySearchSuggest(value));
|
||||
}
|
||||
@ -68,23 +64,20 @@ class SSearchController extends GetxController {
|
||||
controller.value.clear();
|
||||
searchKeyWord.value = '';
|
||||
searchSuggestList.value = [];
|
||||
clearStream.add(false);
|
||||
}
|
||||
|
||||
// 搜索
|
||||
void submit() {
|
||||
if (searchKeyWord.value == '') {
|
||||
if (searchKeyWord.value == '' && hintText.isNotEmpty && hintText == '搜索') {
|
||||
return;
|
||||
} else {
|
||||
if (searchKeyWord.value == '' && hintText != '搜索') {
|
||||
searchKeyWord.value = hintText;
|
||||
controller.value.text = hintText;
|
||||
}
|
||||
}
|
||||
List arr = historyCacheList.where((e) => e != searchKeyWord.value).toList();
|
||||
arr.insert(0, searchKeyWord.value);
|
||||
historyCacheList = arr;
|
||||
|
||||
historyList.value = historyCacheList;
|
||||
// 手动刷新
|
||||
historyList.refresh();
|
||||
localCache.put('cacheList', historyCacheList);
|
||||
searchFocusNode.unfocus();
|
||||
hintText = '搜索';
|
||||
cacheHistory();
|
||||
Get.toNamed('/searchResult', parameters: {'keyword': searchKeyWord.value});
|
||||
}
|
||||
|
||||
@ -135,6 +128,18 @@ class SSearchController extends GetxController {
|
||||
historyCacheList = [];
|
||||
historyList.refresh();
|
||||
localCache.put('cacheList', []);
|
||||
GlobalDataCache().historyCacheList = [];
|
||||
SmartDialog.showToast('搜索历史已清空');
|
||||
}
|
||||
|
||||
cacheHistory() {
|
||||
List arr = historyCacheList.where((e) => e != searchKeyWord.value).toList();
|
||||
arr.insert(0, searchKeyWord.value);
|
||||
historyCacheList = arr;
|
||||
historyList.value = historyCacheList;
|
||||
historyList.refresh();
|
||||
localCache.put('cacheList', historyCacheList);
|
||||
GlobalDataCache().historyCacheList = historyCacheList;
|
||||
searchFocusNode.unfocus();
|
||||
}
|
||||
}
|
||||
|
||||
@ -63,24 +63,35 @@ class _SearchPageState extends State<SearchPage> with RouteAware {
|
||||
focusNode: _searchController.searchFocusNode,
|
||||
controller: _searchController.controller.value,
|
||||
textInputAction: TextInputAction.search,
|
||||
onChanged: (value) => _searchController.onChange(value),
|
||||
onChanged: _searchController.onChange,
|
||||
decoration: InputDecoration(
|
||||
hintText: _searchController.hintText,
|
||||
border: InputBorder.none,
|
||||
suffixIcon: StreamBuilder(
|
||||
initialData: false,
|
||||
stream: _searchController.clearStream.stream,
|
||||
builder: (_, snapshot) {
|
||||
if (snapshot.data == true) {
|
||||
return IconButton(
|
||||
suffix: Obx(() {
|
||||
RxString searchKeyWord = _searchController.searchKeyWord;
|
||||
if (searchKeyWord.value.isEmpty) {
|
||||
return const SizedBox();
|
||||
}
|
||||
return Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
if (RegExp(r'^\d+$').hasMatch(searchKeyWord.value))
|
||||
IconButton(
|
||||
tooltip: '直达up主页',
|
||||
icon: const Icon(Icons.person_outline, size: 22),
|
||||
onPressed: () {
|
||||
_searchController.cacheHistory();
|
||||
Get.toNamed('/member?mid=${searchKeyWord.value}',
|
||||
arguments: {'face': null});
|
||||
},
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.clear, size: 22),
|
||||
onPressed: () => _searchController.onClear(),
|
||||
);
|
||||
} else {
|
||||
return const SizedBox();
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}),
|
||||
),
|
||||
onSubmitted: (String value) => _searchController.submit(),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user