diff --git a/lib/models/common/pgc_review_type.dart b/lib/models/common/pgc_review_type.dart index f1d056f57..f652401ee 100644 --- a/lib/models/common/pgc_review_type.dart +++ b/lib/models/common/pgc_review_type.dart @@ -11,3 +11,12 @@ enum PgcReviewType { required this.api, }); } + +enum PgcReviewSortType { + def('默认', 0), + latest('最新', 1); + + final int sort; + final String label; + const PgcReviewSortType(this.label, this.sort); +} diff --git a/lib/models/pgc/pgc_review/data.dart b/lib/models/pgc/pgc_review/data.dart index 9b249e642..ddd2511ca 100644 --- a/lib/models/pgc/pgc_review/data.dart +++ b/lib/models/pgc/pgc_review/data.dart @@ -12,6 +12,6 @@ class PgcReviewData { ?.map((e) => PgcReviewItemModel.fromJson(e as Map)) .toList(), next: json['next'] as String?, - count: json['count'] as int?, + count: json['count'] ?? json['total'], ); } diff --git a/lib/pages/pgc_review/child/controller.dart b/lib/pages/pgc_review/child/controller.dart index e0a915a80..ed8979616 100644 --- a/lib/pages/pgc_review/child/controller.dart +++ b/lib/pages/pgc_review/child/controller.dart @@ -5,6 +5,7 @@ import 'package:PiliPlus/models/pgc/pgc_review/data.dart'; import 'package:PiliPlus/models/pgc/pgc_review/list.dart'; import 'package:PiliPlus/pages/common/common_list_controller.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; +import 'package:get/get.dart'; class PgcReviewController extends CommonListController { @@ -13,8 +14,9 @@ class PgcReviewController final PgcReviewType type; final dynamic mediaId; - int? count; + Rx count = Rx(null); String? next; + Rx sortType = PgcReviewSortType.def.obs; @override void onInit() { @@ -24,22 +26,28 @@ class PgcReviewController @override Future onRefresh() { - count = null; + count.value = null; next = null; return super.onRefresh(); } @override void checkIsEnd(int length) { - if (count != null && length >= count!) { + if (count.value != null && length >= count.value!) { isEnd = true; } } @override List? getDataList(PgcReviewData response) { - count = response.count; + if (type == PgcReviewType.long && + sortType.value == PgcReviewSortType.latest) { + count.value = null; + } else { + count.value = response.count; + } next = response.next; + return response.list; } @@ -48,6 +56,7 @@ class PgcReviewController type: type, mediaId: mediaId, next: next, + sort: sortType.value.sort, ); Future onLike(int index, bool isLike, reviewId) async { @@ -104,4 +113,11 @@ class PgcReviewController SmartDialog.showToast(res['msg']); } } + + void queryBySort() { + sortType.value = sortType.value == PgcReviewSortType.def + ? PgcReviewSortType.latest + : PgcReviewSortType.def; + onReload(); + } } diff --git a/lib/pages/pgc_review/child/view.dart b/lib/pages/pgc_review/child/view.dart index ef5317308..9355471ba 100644 --- a/lib/pages/pgc_review/child/view.dart +++ b/lib/pages/pgc_review/child/view.dart @@ -1,5 +1,6 @@ import 'package:PiliPlus/common/skeleton/video_reply.dart'; import 'package:PiliPlus/common/widgets/custom_icon.dart'; +import 'package:PiliPlus/common/widgets/custom_sliver_persistent_header_delegate.dart'; import 'package:PiliPlus/common/widgets/dialog/dialog.dart'; import 'package:PiliPlus/common/widgets/image/network_img_layer.dart'; import 'package:PiliPlus/common/widgets/loading_widget/http_error.dart'; @@ -58,9 +59,10 @@ class _PgcReviewChildPageState extends State controller: _controller.scrollController, physics: const AlwaysScrollableScrollPhysics(), slivers: [ + _buildHeader(theme), SliverPadding( padding: EdgeInsets.only( - bottom: MediaQuery.paddingOf(context).bottom + 80), + bottom: MediaQuery.paddingOf(context).bottom + 100), sliver: Obx(() => _buildBody(theme, _controller.loadingState.value)), ), @@ -356,6 +358,52 @@ class _PgcReviewChildPageState extends State ); } + Widget _buildHeader(ThemeData theme) => SliverPersistentHeader( + pinned: false, + floating: true, + delegate: CustomSliverPersistentHeaderDelegate( + extent: 40, + bgColor: theme.colorScheme.surface, + child: Container( + height: 40, + padding: const EdgeInsets.fromLTRB(12, 0, 6, 0), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Obx( + () => _controller.count.value == null + ? const SizedBox.shrink() + : Text( + '${_controller.count.value}条点评', + style: const TextStyle(fontSize: 13), + ), + ), + SizedBox( + height: 35, + child: TextButton.icon( + onPressed: _controller.queryBySort, + icon: Icon( + Icons.sort, + size: 16, + color: theme.colorScheme.secondary, + ), + label: Obx( + () => Text( + _controller.sortType.value.label, + style: TextStyle( + fontSize: 13, + color: theme.colorScheme.secondary, + ), + ), + ), + ), + ) + ], + ), + ), + ), + ); + @override bool get wantKeepAlive => true; }