From 59e2f64164f51a8b92ad7ebfe6227b9c8219c10e Mon Sep 17 00:00:00 2001 From: bggRGjQaUbCoE Date: Fri, 29 Nov 2024 10:52:08 +0800 Subject: [PATCH] opt: fav search page Signed-off-by: bggRGjQaUbCoE --- lib/pages/fav_search/controller.dart | 60 ++++++++++++---------------- lib/pages/fav_search/view.dart | 38 +++++++++--------- 2 files changed, 44 insertions(+), 54 deletions(-) diff --git a/lib/pages/fav_search/controller.dart b/lib/pages/fav_search/controller.dart index 7fb55f56..e946bba2 100644 --- a/lib/pages/fav_search/controller.dart +++ b/lib/pages/fav_search/controller.dart @@ -10,18 +10,14 @@ import 'package:PiliPalaX/http/user.dart'; import '../../http/video.dart'; class FavSearchController extends CommonController { - Rx controller = TextEditingController().obs; - final FocusNode searchFocusNode = FocusNode(); - RxString searchKeyWord = ''.obs; // 搜索词 - String hintText = '搜索'; // 默认 - RxString loadingText = '加载中...'.obs; // 加载提示 + final controller = TextEditingController(); + final searchFocusNode = FocusNode(); + int? type; int? mediaId; int? mid; late SearchType searchType; - int count = 0; // 总数 - @override void onInit() { super.onInit(); @@ -33,9 +29,8 @@ class FavSearchController extends CommonController { // 清空搜索 void onClear() { - if (searchKeyWord.value.isNotEmpty && controller.value.text != '') { - controller.value.clear(); - searchKeyWord.value = ''; + if (controller.text.isNotEmpty) { + controller.clear(); } else { Get.back(); } @@ -49,10 +44,6 @@ class FavSearchController extends CommonController { return super.onRefresh(); } - void onChange(value) { - searchKeyWord.value = value; - } - @override bool customHandleResponse(Success response) { List currentList = loadingState.value is Success @@ -81,36 +72,37 @@ class FavSearchController extends CommonController { ); if (result['status']) { List dataList = (loadingState.value as Success).response; - dataList = dataList.where((item) => item.id != id).toList(); + dataList.removeWhere((item) => item.id != id); loadingState.value = LoadingState.success(dataList); SmartDialog.showToast('取消收藏'); } } @override - Future customGetData() => searchType == SearchType.fav - ? UserHttp.userFavFolderDetail( - pn: currentPage, - ps: 20, - mediaId: mediaId!, - keyword: searchKeyWord.value, - type: type!, - ) - : searchType == SearchType.follow - ? MemberHttp.getfollowSearch( - mid: mid!, - ps: 20, - pn: currentPage, - name: controller.value.text, - ) - : UserHttp.searchHistory( - pn: currentPage, - keyword: controller.value.text, - ); + Future customGetData() => switch (searchType) { + SearchType.fav => UserHttp.userFavFolderDetail( + pn: currentPage, + ps: 20, + mediaId: mediaId!, + keyword: controller.text, + type: type!, + ), + SearchType.follow => MemberHttp.getfollowSearch( + mid: mid!, + ps: 20, + pn: currentPage, + name: controller.value.text, + ), + SearchType.history => UserHttp.searchHistory( + pn: currentPage, + keyword: controller.value.text, + ), + }; @override void onClose() { searchFocusNode.dispose(); + controller.dispose(); super.onClose(); } diff --git a/lib/pages/fav_search/view.dart b/lib/pages/fav_search/view.dart index 8f979914..c4215867 100644 --- a/lib/pages/fav_search/view.dart +++ b/lib/pages/fav_search/view.dart @@ -29,30 +29,28 @@ class _FavSearchPageState extends State { appBar: AppBar( actions: [ IconButton( - tooltip: '搜索', - onPressed: _favSearchCtr.onRefresh, - icon: const Icon(Icons.search_outlined, size: 22)), + tooltip: '搜索', + onPressed: _favSearchCtr.onRefresh, + icon: const Icon(Icons.search_outlined, size: 22), + ), const SizedBox(width: 10) ], - title: Obx( - () => TextField( - autofocus: true, - focusNode: _favSearchCtr.searchFocusNode, - controller: _favSearchCtr.controller.value, - textInputAction: TextInputAction.search, - onChanged: (value) => _favSearchCtr.onChange(value), - textAlignVertical: TextAlignVertical.center, - decoration: InputDecoration( - hintText: _favSearchCtr.hintText, - border: InputBorder.none, - suffixIcon: IconButton( - tooltip: '清空', - icon: const Icon(Icons.clear, size: 22), - onPressed: () => _favSearchCtr.onClear(), - ), + title: TextField( + autofocus: true, + focusNode: _favSearchCtr.searchFocusNode, + controller: _favSearchCtr.controller, + textInputAction: TextInputAction.search, + textAlignVertical: TextAlignVertical.center, + decoration: InputDecoration( + hintText: '搜索', + border: InputBorder.none, + suffixIcon: IconButton( + tooltip: '清空', + icon: const Icon(Icons.clear, size: 22), + onPressed: _favSearchCtr.onClear, ), - onSubmitted: (String value) => _favSearchCtr.onRefresh(), ), + onSubmitted: (value) => _favSearchCtr.onRefresh(), ), ), body: Obx(() => _buildBody(_favSearchCtr.loadingState.value)),