feat: UP主投稿排序查询
This commit is contained in:
@ -5,20 +5,38 @@ class ArchiveController extends GetxController {
|
|||||||
int? mid;
|
int? mid;
|
||||||
int pn = 1;
|
int pn = 1;
|
||||||
int count = 0;
|
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
|
@override
|
||||||
void onInit() {
|
void onInit() {
|
||||||
super.onInit();
|
super.onInit();
|
||||||
mid = int.parse(Get.parameters['mid']!);
|
mid = int.parse(Get.parameters['mid']!);
|
||||||
|
currentOrder.value = orderList.first;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取用户投稿
|
// 获取用户投稿
|
||||||
Future getMemberArchive() async {
|
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']) {
|
if (res['status']) {
|
||||||
count = res['data'].page['count'];
|
count = res['data'].page['count'];
|
||||||
pn += 1;
|
pn += 1;
|
||||||
}
|
}
|
||||||
return res;
|
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];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,6 +18,8 @@ class _ArchivePanelState extends State<ArchivePanel>
|
|||||||
with AutomaticKeepAliveClientMixin {
|
with AutomaticKeepAliveClientMixin {
|
||||||
DateTime lastRefreshTime = DateTime.now();
|
DateTime lastRefreshTime = DateTime.now();
|
||||||
late final LoadMoreListSource source = LoadMoreListSource();
|
late final LoadMoreListSource source = LoadMoreListSource();
|
||||||
|
final ArchiveController _archiveController =
|
||||||
|
Get.put(ArchiveController(), tag: Get.arguments['heroTag']);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool get wantKeepAlive => true;
|
bool get wantKeepAlive => true;
|
||||||
@ -40,14 +42,63 @@ class _ArchivePanelState extends State<ArchivePanel>
|
|||||||
// return PullToRefreshHeader(info, lastRefreshTime);
|
// 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(
|
Expanded(
|
||||||
child: LoadingMoreList<VListItemModel>(
|
child: LoadingMoreList<VListItemModel>(
|
||||||
ListConfig<VListItemModel>(
|
ListConfig<VListItemModel>(
|
||||||
sourceList: source,
|
sourceList: source,
|
||||||
itemBuilder:
|
itemBuilder:
|
||||||
(BuildContext c, VListItemModel item, int index) {
|
(BuildContext c, VListItemModel item, int index) {
|
||||||
|
if (index == 0) {
|
||||||
|
return Column(
|
||||||
|
children: [
|
||||||
|
const SizedBox(height: 6),
|
||||||
|
VideoCardH(videoItem: item)
|
||||||
|
],
|
||||||
|
);
|
||||||
|
} else {
|
||||||
return VideoCardH(videoItem: item);
|
return VideoCardH(videoItem: item);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
indicatorBuilder: _buildIndicator,
|
indicatorBuilder: _buildIndicator,
|
||||||
),
|
),
|
||||||
@ -144,12 +195,16 @@ class _ArchivePanelState extends State<ArchivePanel>
|
|||||||
class LoadMoreListSource extends LoadingMoreBase<VListItemModel> {
|
class LoadMoreListSource extends LoadingMoreBase<VListItemModel> {
|
||||||
final ArchiveController _archiveController =
|
final ArchiveController _archiveController =
|
||||||
Get.put(ArchiveController(), tag: Get.arguments['heroTag']);
|
Get.put(ArchiveController(), tag: Get.arguments['heroTag']);
|
||||||
|
bool forceRefresh = false;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<bool> loadData([bool isloadMoreAction = false]) async {
|
Future<bool> loadData([bool isloadMoreAction = false]) async {
|
||||||
bool isSuccess = false;
|
bool isSuccess = false;
|
||||||
var res = await _archiveController.getMemberArchive();
|
var res = await _archiveController.getMemberArchive();
|
||||||
if (res['status']) {
|
if (res['status']) {
|
||||||
|
if (_archiveController.pn == 2) {
|
||||||
|
clear();
|
||||||
|
}
|
||||||
addAll(res['data'].list.vlist);
|
addAll(res['data'].list.vlist);
|
||||||
}
|
}
|
||||||
if (length < res['data'].page['count']) {
|
if (length < res['data'].page['count']) {
|
||||||
@ -159,4 +214,17 @@ class LoadMoreListSource extends LoadingMoreBase<VListItemModel> {
|
|||||||
}
|
}
|
||||||
return isSuccess;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -721,18 +721,18 @@ packages:
|
|||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: loading_more_list
|
name: loading_more_list
|
||||||
sha256: aa680edc81cf024c394dccfa7ba1db701a5efb23ec1b8c657308428ce9da11d1
|
sha256: "6b49eb935345d6cf291e0367d3c238ef0a525a08b671ee41e09ee67d41888a7a"
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "5.0.3"
|
version: "6.0.0"
|
||||||
loading_more_list_library:
|
loading_more_list_library:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: loading_more_list_library
|
name: loading_more_list_library
|
||||||
sha256: "31348925a98748ffe04f661e4b47df37103fabad39442064fcf59148a5fee2dd"
|
sha256: de6b57edbab83022180f053ec3f598dd5e1192cfd6a285882b8155e3cb5dc581
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.0.1"
|
version: "3.0.0"
|
||||||
logging:
|
logging:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|||||||
@ -70,7 +70,7 @@ dependencies:
|
|||||||
# 解决sliver滑动不同步
|
# 解决sliver滑动不同步
|
||||||
extended_nested_scroll_view: ^6.1.2
|
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
|
pull_to_refresh_notification: ^3.0.1
|
||||||
# 图标
|
# 图标
|
||||||
|
|||||||
Reference in New Issue
Block a user