diff --git a/lib/pages/search_panel/controller.dart b/lib/pages/search_panel/controller.dart index f1b5aaa7..ddcd261e 100644 --- a/lib/pages/search_panel/controller.dart +++ b/lib/pages/search_panel/controller.dart @@ -8,9 +8,13 @@ import 'package:PiliPlus/utils/id_utils.dart'; import 'package:PiliPlus/utils/utils.dart'; class SearchPanelController extends CommonController { - SearchPanelController({this.keyword, this.searchType, this.tag}); + SearchPanelController({ + this.keyword, + required this.searchType, + required this.tag, + }); String? keyword; - SearchType? searchType; + SearchType searchType; // 结果排序方式 搜索类型为视频、专栏及相簿时 RxString order = ''.obs; // 视频时长筛选 仅用于搜索视频 @@ -19,11 +23,9 @@ class SearchPanelController extends CommonController { int? orderSort; int? userType; int? categoryId; - String? tag; + String tag; int? pubBegin; int? pubEnd; - late final searchResultController = - Get.find(tag: tag); @override void onInit() { @@ -33,8 +35,10 @@ class SearchPanelController extends CommonController { @override bool customHandleResponse(Success response) { - searchResultController.count[SearchType.values.indexOf(searchType!)] = - response.response.numResults; + try { + Get.find(tag: tag).count[searchType.index] = + response.response.numResults; + } catch (_) {} if (response.response.list != null) { isEnd = response.response.list.isEmpty; if (currentPage != 1 && loadingState.value is Success) { @@ -94,11 +98,11 @@ class SearchPanelController extends CommonController { @override Future customGetData() => SearchHttp.searchByType( - searchType: searchType!, + searchType: searchType, keyword: keyword!, page: currentPage, order: order.value, - duration: searchType!.name != 'video' ? null : duration.value, + duration: searchType.name != 'video' ? null : duration.value, tids: tids, orderSort: orderSort, userType: userType, diff --git a/lib/pages/search_panel/view.dart b/lib/pages/search_panel/view.dart index d465016e..624434f3 100644 --- a/lib/pages/search_panel/view.dart +++ b/lib/pages/search_panel/view.dart @@ -17,13 +17,13 @@ import 'widgets/user_panel.dart'; class SearchPanel extends StatefulWidget { final String? keyword; - final SearchType? searchType; - final String? tag; + final SearchType searchType; + final String tag; const SearchPanel({ super.key, required this.keyword, required this.searchType, - this.tag, + required this.tag, }); @override @@ -46,7 +46,7 @@ class _SearchPanelState extends State searchType: widget.searchType, tag: widget.tag, ), - tag: widget.searchType!.name + widget.keyword!, + tag: widget.searchType.name + widget.keyword!, ); } diff --git a/lib/pages/search_result/view.dart b/lib/pages/search_result/view.dart index 2f9dbb08..b1206578 100644 --- a/lib/pages/search_result/view.dart +++ b/lib/pages/search_result/view.dart @@ -84,8 +84,7 @@ class _SearchResultPageState extends State .map( (item) => Obx( () { - int count = _searchResultController - .count[SearchType.values.indexOf(item)]; + int count = _searchResultController.count[item.index]; return Tab( text: '${item.label}${count != -1 ? ' ${count > 99 ? '99+' : count}' : ''}');