mod: 评论刷新、翻页

This commit is contained in:
guozhigq
2023-04-28 12:48:45 +08:00
parent c6c4138640
commit 6fbfd2db9e
7 changed files with 324 additions and 238 deletions

View File

@ -1,22 +1,62 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:pilipala/http/reply.dart';
import 'package:pilipala/models/video/reply/data.dart';
import 'package:pilipala/models/video/reply/item.dart';
class VideoReplyController extends GetxController {
final ScrollController scrollController = ScrollController();
// 视频aid
String aid = Get.parameters['aid']!;
RxList<ReplyItemModel> replyList = [ReplyItemModel()].obs;
// 当前页
int currentPage = 0;
bool isLoadingMore = false;
bool noMore = false;
@override
void onInit() {
super.onInit();
queryReplyList();
}
Future queryReplyList() async {
var res = await ReplyHttp.replyList(oid: aid, pageNum: 1, type: 1);
Future queryReplyList({type = 'init'}) async {
isLoadingMore = true;
var res =
await ReplyHttp.replyList(oid: aid, pageNum: currentPage + 1, type: 1);
if (res['status']) {
res['data'] = ReplyData.fromJson(res['data']);
if (res['data'].replies.isNotEmpty) {
currentPage = currentPage + 1;
noMore = false;
} else {
if (currentPage == 0) {
} else {
noMore = true;
}
}
if (type == 'init') {
List<ReplyItemModel> replies = res['data'].replies;
// 添加置顶回复
if (res['data'].upper.top != null) {
bool flag = false;
for (var i = 0; i < res['data'].topReplies.length; i++) {
if (res['data'].topReplies[i].rpid == res['data'].upper.top.rpid) {
flag = true;
}
}
if (!flag) {
replies.insert(0, res['data'].upper.top);
}
}
replies.insertAll(0, res['data'].topReplies);
res['data'].replies = replies;
replyList.value = res['data'].replies!;
} else {
replyList.addAll(res['data'].replies!);
res['data'].replies.addAll(replyList);
}
}
isLoadingMore = false;
return res;
}
// 上拉加载
Future onLoad() async {
queryReplyList(type: 'onLoad');
}
}