From d34f1660375ce31ef89b64202eb8844e43cf0002 Mon Sep 17 00:00:00 2001 From: guozhigq Date: Sat, 25 May 2024 16:16:23 +0800 Subject: [PATCH] =?UTF-8?q?mod:=20=E5=8E=86=E5=8F=B2=E8=AE=B0=E5=BD=95?= =?UTF-8?q?=E6=90=9C=E7=B4=A2=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/pages/history/widgets/item.dart | 2 +- lib/pages/history_search/controller.dart | 12 +- lib/pages/history_search/view.dart | 150 ++++++++--------------- 3 files changed, 59 insertions(+), 105 deletions(-) diff --git a/lib/pages/history/widgets/item.dart b/lib/pages/history/widgets/item.dart index 00ebd511..baebfedb 100644 --- a/lib/pages/history/widgets/item.dart +++ b/lib/pages/history/widgets/item.dart @@ -244,7 +244,7 @@ class HistoryItem extends StatelessWidget { ), ), ), - videoItem.progress != 0 + videoItem.progress != 0 && videoItem.duration != 0 ? Positioned( left: 3, right: 3, diff --git a/lib/pages/history_search/controller.dart b/lib/pages/history_search/controller.dart index 90ac7a02..a6c79e6a 100644 --- a/lib/pages/history_search/controller.dart +++ b/lib/pages/history_search/controller.dart @@ -10,9 +10,8 @@ class HistorySearchController extends GetxController { final FocusNode searchFocusNode = FocusNode(); RxString searchKeyWord = ''.obs; String hintText = '搜索'; - RxString loadingStatus = 'init'.obs; + RxBool loadingStatus = false.obs; RxString loadingText = '加载中...'.obs; - bool hasRequest = false; late int mid; RxString uname = ''.obs; int pn = 1; @@ -36,8 +35,7 @@ class HistorySearchController extends GetxController { // 提交搜索内容 void submit() { - loadingStatus.value = 'loading'; - if (hasRequest) { + if (!loadingStatus.value) { pn = 1; searchHistories(); } @@ -48,6 +46,7 @@ class HistorySearchController extends GetxController { if (type == 'onLoad' && loadingText.value == '没有更多了') { return; } + loadingStatus.value = true; var res = await UserHttp.searchHistory( pn: pn, keyword: controller.value.text, @@ -63,9 +62,8 @@ class HistorySearchController extends GetxController { loadingText.value = '没有更多了'; } pn += 1; - hasRequest = true; } - loadingStatus.value = 'finish'; + loadingStatus.value = false; return res; } @@ -86,6 +84,6 @@ class HistorySearchController extends GetxController { historyList.removeWhere((e) => e.kid == kid); SmartDialog.showToast(res['msg']); } - loadingStatus.value = 'finish'; + // loadingStatus.value = fasle; } } diff --git a/lib/pages/history_search/view.dart b/lib/pages/history_search/view.dart index 5bde691d..f5bcae64 100644 --- a/lib/pages/history_search/view.dart +++ b/lib/pages/history_search/view.dart @@ -2,7 +2,6 @@ import 'package:easy_debounce/easy_throttle.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:pilipala/common/skeleton/video_card_h.dart'; -import 'package:pilipala/common/widgets/http_error.dart'; import 'package:pilipala/common/widgets/no_data.dart'; import 'package:pilipala/pages/history/widgets/item.dart'; @@ -16,20 +15,19 @@ class HistorySearchPage extends StatefulWidget { } class _HistorySearchPageState extends State { - final HistorySearchController _historySearchCtr = - Get.put(HistorySearchController()); + final HistorySearchController _hisCtr = Get.put(HistorySearchController()); late ScrollController scrollController; @override void initState() { super.initState(); - scrollController = _historySearchCtr.scrollController; + scrollController = _hisCtr.scrollController; scrollController.addListener( () { if (scrollController.position.pixels >= scrollController.position.maxScrollExtent - 300) { EasyThrottle.throttle('history', const Duration(seconds: 1), () { - _historySearchCtr.onLoad(); + _hisCtr.onLoad(); }); } }, @@ -50,19 +48,19 @@ class _HistorySearchPageState extends State { titleSpacing: 0, actions: [ IconButton( - onPressed: () => _historySearchCtr.submit(), + onPressed: () => _hisCtr.submit(), icon: const Icon(Icons.search_outlined, size: 22)), const SizedBox(width: 10) ], title: Obx( () => TextField( autofocus: true, - focusNode: _historySearchCtr.searchFocusNode, - controller: _historySearchCtr.controller.value, + focusNode: _hisCtr.searchFocusNode, + controller: _hisCtr.controller.value, textInputAction: TextInputAction.search, - onChanged: (value) => _historySearchCtr.onChange(value), + onChanged: (value) => _hisCtr.onChange(value), decoration: InputDecoration( - hintText: _historySearchCtr.hintText, + hintText: _hisCtr.hintText, border: InputBorder.none, suffixIcon: IconButton( icon: Icon( @@ -70,103 +68,61 @@ class _HistorySearchPageState extends State { size: 22, color: Theme.of(context).colorScheme.outline, ), - onPressed: () => _historySearchCtr.onClear(), + onPressed: () => _hisCtr.onClear(), ), ), - onSubmitted: (String value) => _historySearchCtr.submit(), + onSubmitted: (String value) => _hisCtr.submit(), ), ), ), 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(() {}), - ) - ], - ); - } + () { + return _hisCtr.loadingStatus.value && _hisCtr.historyList.isEmpty + ? ListView.builder( + itemCount: 10, + itemBuilder: (context, index) { + return const VideoCardHSkeleton(); + }, + ) + : _hisCtr.historyList.isNotEmpty + ? ListView.builder( + controller: scrollController, + itemCount: _hisCtr.historyList.length + 1, + itemBuilder: (context, index) { + if (index == _hisCtr.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( + _hisCtr.loadingText.value, + style: TextStyle( + color: + Theme.of(context).colorScheme.outline, + fontSize: 13, + ), + ), + ), + ), + ); } else { - // 骨架屏 - return ListView.builder( - itemCount: 10, - itemBuilder: (context, index) { - return const VideoCardHSkeleton(); - }, + return HistoryItem( + videoItem: _hisCtr.historyList[index], + ctr: _hisCtr, + onChoose: null, + onUpdateMultiple: () => null, ); } }, - ), - ), - ], - ), + ) + : const CustomScrollView( + slivers: [ + NoData(), + ], + ); + }, ), ); }