diff --git a/lib/pages/history_search/controller.dart b/lib/pages/history_search/controller.dart index 74ec1080..cc114577 100644 --- a/lib/pages/history_search/controller.dart +++ b/lib/pages/history_search/controller.dart @@ -12,7 +12,6 @@ class HistorySearchController extends GetxController { String hintText = '搜索'; RxString loadingStatus = 'init'.obs; RxString loadingText = '加载中...'.obs; - bool hasRequest = false; late int mid; RxString uname = ''.obs; int pn = 1; @@ -37,10 +36,8 @@ class HistorySearchController extends GetxController { // 提交搜索内容 void submit() { loadingStatus.value = 'loading'; - if (hasRequest) { - pn = 1; - searchHistories(); - } + pn = 1; + searchHistories(); } // 搜索视频 @@ -58,18 +55,18 @@ class HistorySearchController extends GetxController { } else { historyList.addAll(res['data'].list); } + historyList.refresh(); count = res['data'].page['total']; if (historyList.length == count) { loadingText.value = '没有更多了'; } - pn += 1; - hasRequest = true; } loadingStatus.value = 'finish'; - return res; + // return res; } onLoad() { + pn += 1; searchHistories(type: 'onLoad'); } diff --git a/lib/pages/history_search/view.dart b/lib/pages/history_search/view.dart index c6a2a727..f75dee02 100644 --- a/lib/pages/history_search/view.dart +++ b/lib/pages/history_search/view.dart @@ -6,6 +6,8 @@ import 'package:PiliPalaX/common/widgets/http_error.dart'; import 'package:PiliPalaX/common/widgets/no_data.dart'; import 'package:PiliPalaX/pages/history/widgets/item.dart'; +import '../../common/constants.dart'; +import '../../utils/grid.dart'; import 'controller.dart'; class HistorySearchPage extends StatefulWidget { @@ -80,95 +82,34 @@ class _HistorySearchPageState extends State { ), ), body: Obx( - () => Column( - children: _historySearchCtr.loadingStatus.value == 'init' - ? [const SizedBox()] - : [ - Expanded( - child: FutureBuilder( - future: _historySearchCtr.searchHistories(), - builder: (context, snapshot) { - if (snapshot.connectionState == ConnectionState.done) { - Map data = snapshot.data as Map; - if (data['status']) { - return Obx( - () => _historySearchCtr.historyList.isNotEmpty - ? ListView.builder( - controller: scrollController, - itemCount: - _historySearchCtr.historyList.length + - 1, - itemBuilder: (context, index) { - if (index == - _historySearchCtr - .historyList.length) { - return Container( - height: MediaQuery.of(context) - .padding - .bottom + - 60, - padding: EdgeInsets.only( - bottom: MediaQuery.of(context) - .padding - .bottom), - child: Center( - child: Obx( - () => Text( - _historySearchCtr - .loadingText.value, - style: TextStyle( - color: Theme.of(context) - .colorScheme - .outline, - fontSize: 13), - ), - ), - ), - ); - } else { - return HistoryItem( - videoItem: _historySearchCtr - .historyList[index], - ctr: _historySearchCtr, - onChoose: null, - onUpdateMultiple: () => null, - ); - } - }, - ) - : _historySearchCtr.loadingStatus.value == - 'loading' - ? const SizedBox(child: Text('加载中...')) - : const CustomScrollView( - slivers: [ - NoData(), - ], - ), - ); - } else { - return CustomScrollView( - slivers: [ - HttpError( - errMsg: data['msg'], - fn: () => setState(() {}), - ) - ], - ); - } - } else { - // 骨架屏 - return ListView.builder( - itemCount: 10, - itemBuilder: (context, index) { - return const VideoCardHSkeleton(); - }, + () => _historySearchCtr.loadingStatus.value == 'init' + ? const SizedBox() + : CustomScrollView( + physics: const AlwaysScrollableScrollPhysics(), + controller: scrollController, + slivers: [ + Obx(() => SliverGrid( + gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent( + mainAxisSpacing: StyleString.cardSpace, + crossAxisSpacing: StyleString.safeSpace, + maxCrossAxisExtent: Grid.maxRowWidth * 2, + mainAxisExtent: Grid.calculateActualWidth(context, + Grid.maxRowWidth * 2, StyleString.safeSpace) / + 2.1 / + StyleString.aspectRatio), + delegate: SliverChildBuilderDelegate( + (context, index) { + return HistoryItem( + videoItem: _historySearchCtr.historyList[index], + ctr: _historySearchCtr, + onChoose: null, + onUpdateMultiple: () => null, ); - } - }, - ), - ), + }, + childCount: _historySearchCtr.historyList.length, + ))) ], - ), + ), ), ); }