opt search

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
bggRGjQaUbCoE
2025-07-26 12:38:54 +08:00
parent d17dbe139e
commit bb36876d1e
6 changed files with 31 additions and 29 deletions

View File

@@ -24,7 +24,7 @@ class HomeController extends GetxController
final bool hideSearchBar = Pref.hideSearchBar;
final bool useSideBar = Pref.useSideBar;
final bool enableSearchWord = Pref.enableSearchWord;
bool enableSearchWord = Pref.enableSearchWord;
late RxString defaultSearch = ''.obs;
late int lateCheckSearchAt = 0;

View File

@@ -204,19 +204,17 @@ class _HomePageState extends State<HomePage>
semanticLabel: '搜索',
),
const SizedBox(width: 10),
if (_homeController.enableSearchWord) ...[
Expanded(
child: Obx(
() => Text(
_homeController.defaultSearch.value,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(color: theme.colorScheme.outline),
),
Expanded(
child: Obx(
() => Text(
_homeController.defaultSearch.value,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(color: theme.colorScheme.outline),
),
),
const SizedBox(width: 2),
],
),
const SizedBox(width: 5),
],
),
),

View File

@@ -39,6 +39,7 @@ class _MainAppState extends State<MainApp>
late final _homeController = Get.put(HomeController());
late final _dynamicController = Get.put(DynamicsController());
static const _period = 5 * 60 * 1000;
late int _lastSelectTime = 0;
@override
@@ -85,7 +86,7 @@ class _MainAppState extends State<MainApp>
return;
}
int now = DateTime.now().millisecondsSinceEpoch;
if (now - _homeController.lateCheckSearchAt >= 5 * 60 * 1000) {
if (now - _homeController.lateCheckSearchAt >= _period) {
_homeController
..lateCheckSearchAt = now
..querySearchDefault();
@@ -103,7 +104,7 @@ class _MainAppState extends State<MainApp>
return;
}
int now = DateTime.now().millisecondsSinceEpoch;
if (now - _mainController.lastCheckUnreadAt >= 5 * 60 * 1000) {
if (now - _mainController.lastCheckUnreadAt >= _period) {
_mainController
..lastCheckUnreadAt = now
..queryUnreadMsg();

View File

@@ -6,6 +6,7 @@ import 'package:PiliPlus/http/search.dart';
import 'package:PiliPlus/models/search/suggest.dart';
import 'package:PiliPlus/models_new/search/search_rcmd/data.dart';
import 'package:PiliPlus/models_new/search/search_trending/data.dart';
import 'package:PiliPlus/utils/extension.dart';
import 'package:PiliPlus/utils/id_utils.dart';
import 'package:PiliPlus/utils/storage.dart';
import 'package:PiliPlus/utils/storage_pref.dart';
@@ -20,7 +21,7 @@ class SSearchController extends GetxController {
final searchFocusNode = FocusNode();
final controller = TextEditingController();
String hintText = '搜索';
String? hintText;
int initIndex = 0;
@@ -48,15 +49,11 @@ class SSearchController extends GetxController {
@override
void onInit() {
super.onInit();
// 其他页面跳转过来
if (Get.parameters['keyword'] != null) {
onClickKeyword(Get.parameters['keyword']!);
}
if (Get.parameters['hintText'] != null) {
hintText = Get.parameters['hintText']!;
}
if (Get.parameters['text'] != null) {
controller.text = Get.parameters['text']!;
final params = Get.parameters;
hintText = params['hintText'];
final text = params['text'];
if (text != null) {
controller.text = text;
}
historyList = List<String>.from(
@@ -111,10 +108,10 @@ class SSearchController extends GetxController {
// 搜索
Future<void> submit() async {
if (controller.text.isEmpty) {
if (hintText.isEmpty) {
if (hintText.isNullOrEmpty) {
return;
}
controller.text = hintText;
controller.text = hintText!;
validateUid();
}
@@ -126,7 +123,6 @@ class SSearchController extends GetxController {
}
searchFocusNode.unfocus();
await Get.toNamed(
'/searchResult',
parameters: {

View File

@@ -68,7 +68,7 @@ class _SearchPageState extends State<SearchPage> {
textInputAction: TextInputAction.search,
onChanged: _searchController.onChange,
decoration: InputDecoration(
hintText: _searchController.hintText,
hintText: _searchController.hintText ?? '搜索',
border: InputBorder.none,
),
onSubmitted: (value) => _searchController.submit(),

View File

@@ -773,7 +773,14 @@ List<SettingsModel> get extraSettings => [
setKey: SettingBoxKey.enableSearchWord,
defaultVal: true,
onChanged: (val) {
Get.find<HomeController>().defaultSearch.value = '';
try {
final controller = Get.find<HomeController>()..enableSearchWord = val;
if (val) {
controller.querySearchDefault();
} else {
controller.defaultSearch.value = '';
}
} catch (_) {}
},
),
SettingsModel(