feat: UP主投稿排序查询

This commit is contained in:
guozhigq
2023-09-23 00:48:22 +08:00
parent 97268c36dc
commit f79e4765c2
4 changed files with 94 additions and 8 deletions

View File

@ -5,20 +5,38 @@ class ArchiveController extends GetxController {
int? mid;
int pn = 1;
int count = 0;
RxMap<String, String> currentOrder = <String, String>{}.obs;
List<Map<String, String>> orderList = [
{'type': 'pubdate', 'label': '最新发布'},
{'type': 'click', 'label': '最多播放'},
{'type': 'stow', 'label': '最多收藏'},
];
@override
void onInit() {
super.onInit();
mid = int.parse(Get.parameters['mid']!);
currentOrder.value = orderList.first;
}
// 获取用户投稿
Future getMemberArchive() async {
var res = await MemberHttp.memberArchive(mid: mid, pn: pn);
var res = await MemberHttp.memberArchive(
mid: mid, pn: pn, order: currentOrder['type']!);
if (res['status']) {
count = res['data'].page['count'];
pn += 1;
}
return res;
}
toggleSort() async {
pn = 1;
int index = orderList.indexOf(currentOrder.value);
if (index == orderList.length - 1) {
currentOrder.value = orderList.first;
} else {
currentOrder.value = orderList[index + 1];
}
}
}

View File

@ -18,6 +18,8 @@ class _ArchivePanelState extends State<ArchivePanel>
with AutomaticKeepAliveClientMixin {
DateTime lastRefreshTime = DateTime.now();
late final LoadMoreListSource source = LoadMoreListSource();
final ArchiveController _archiveController =
Get.put(ArchiveController(), tag: Get.arguments['heroTag']);
@override
bool get wantKeepAlive => true;
@ -40,14 +42,63 @@ class _ArchivePanelState extends State<ArchivePanel>
// return PullToRefreshHeader(info, lastRefreshTime);
// },
// ),
const SizedBox(height: 4),
Padding(
padding:
const EdgeInsets.only(left: 14, top: 8, bottom: 8, right: 8),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const Text('排序方式'),
SizedBox(
height: 35,
width: 85,
child: TextButton(
style: ButtonStyle(
padding: MaterialStateProperty.all(EdgeInsets.zero),
),
onPressed: () {
// _archiveController.order = 'click';
// _archiveController.pn = 1;
_archiveController.toggleSort();
source.refresh(true);
// LoadMoreListSource().loadData();
},
child: Obx(
() => AnimatedSwitcher(
duration: const Duration(milliseconds: 400),
transitionBuilder:
(Widget child, Animation<double> animation) {
return ScaleTransition(
scale: animation, child: child);
},
child: Text(
_archiveController.currentOrder['label']!,
key: ValueKey<String>(
_archiveController.currentOrder['label']!),
),
),
),
),
),
],
),
),
Expanded(
child: LoadingMoreList<VListItemModel>(
ListConfig<VListItemModel>(
sourceList: source,
itemBuilder:
(BuildContext c, VListItemModel item, int index) {
return VideoCardH(videoItem: item);
if (index == 0) {
return Column(
children: [
const SizedBox(height: 6),
VideoCardH(videoItem: item)
],
);
} else {
return VideoCardH(videoItem: item);
}
},
indicatorBuilder: _buildIndicator,
),
@ -144,12 +195,16 @@ class _ArchivePanelState extends State<ArchivePanel>
class LoadMoreListSource extends LoadingMoreBase<VListItemModel> {
final ArchiveController _archiveController =
Get.put(ArchiveController(), tag: Get.arguments['heroTag']);
bool forceRefresh = false;
@override
Future<bool> loadData([bool isloadMoreAction = false]) async {
bool isSuccess = false;
var res = await _archiveController.getMemberArchive();
if (res['status']) {
if (_archiveController.pn == 2) {
clear();
}
addAll(res['data'].list.vlist);
}
if (length < res['data'].page['count']) {
@ -159,4 +214,17 @@ class LoadMoreListSource extends LoadingMoreBase<VListItemModel> {
}
return isSuccess;
}
@override
Future<bool> refresh([bool clearBeforeRequest = false]) async {
// _hasMore = true;
// pageindex = 1;
// //force to refresh list when you don't want clear list before request
// //for the case, if your list already has 20 items.
forceRefresh = !clearBeforeRequest;
var result = await super.refresh(clearBeforeRequest);
forceRefresh = false;
return result;
}
}

View File

@ -721,18 +721,18 @@ packages:
dependency: "direct main"
description:
name: loading_more_list
sha256: aa680edc81cf024c394dccfa7ba1db701a5efb23ec1b8c657308428ce9da11d1
sha256: "6b49eb935345d6cf291e0367d3c238ef0a525a08b671ee41e09ee67d41888a7a"
url: "https://pub.dev"
source: hosted
version: "5.0.3"
version: "6.0.0"
loading_more_list_library:
dependency: transitive
description:
name: loading_more_list_library
sha256: "31348925a98748ffe04f661e4b47df37103fabad39442064fcf59148a5fee2dd"
sha256: de6b57edbab83022180f053ec3f598dd5e1192cfd6a285882b8155e3cb5dc581
url: "https://pub.dev"
source: hosted
version: "2.0.1"
version: "3.0.0"
logging:
dependency: transitive
description:

View File

@ -70,7 +70,7 @@ dependencies:
# 解决sliver滑动不同步
extended_nested_scroll_view: ^6.1.2
# 上拉加载
loading_more_list: ^5.0.3
loading_more_list: ^6.0.0
# 下拉刷新
pull_to_refresh_notification: ^3.0.1
# 图标