opt: load more

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
bggRGjQaUbCoE
2024-11-27 12:42:27 +08:00
parent 05f9384c72
commit 4a145750c0
12 changed files with 65 additions and 156 deletions

View File

@@ -2,6 +2,7 @@ import 'package:PiliPalaX/common/widgets/refresh_indicator.dart';
import 'package:PiliPalaX/common/widgets/http_error.dart';
import 'package:PiliPalaX/http/loading_state.dart';
import 'package:PiliPalaX/pages/video/detail/reply/widgets/reply_item_grpc.dart';
import 'package:PiliPalaX/utils/extension.dart';
import 'package:easy_debounce/easy_throttle.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
@@ -215,17 +216,18 @@ class _VideoReplyPanelState extends State<VideoReplyPanel>
_videoReplyController.onLoadMore();
});
return Container(
alignment: Alignment.center,
padding: EdgeInsets.only(bottom: bottom),
height: bottom + 100,
child: Center(
child: Obx(
() => Text(
_videoReplyController.noMore.value,
style: TextStyle(
fontSize: 12,
color: Theme.of(context).colorScheme.outline,
),
),
child: Text(
_videoReplyController.isEnd.not
? '加载中...'
: loadingState.response.replies.isEmpty
? '还没有评论'
: '没有更多了',
style: TextStyle(
fontSize: 12,
color: Theme.of(context).colorScheme.outline,
),
),
);

View File

@@ -2,7 +2,6 @@ import 'package:PiliPalaX/grpc/app/main/community/reply/v1/reply.pb.dart';
import 'package:PiliPalaX/grpc/grpc_repo.dart';
import 'package:PiliPalaX/http/loading_state.dart';
import 'package:PiliPalaX/pages/common/common_controller.dart';
import 'package:PiliPalaX/utils/extension.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:PiliPalaX/http/reply.dart';
@@ -44,8 +43,6 @@ class VideoReplyReplyController extends CommonController
ReplyInfo? firstFloor;
bool isEnd = false;
@override
void onInit() {
super.onInit();
@@ -82,7 +79,6 @@ class VideoReplyReplyController extends CommonController
@override
Future queryData([bool isRefresh = true]) async {
if (isRefresh.not && isEnd) return Future.value();
if (!isDialogue &&
currentPage == 1 &&
!hasRoot &&
@@ -110,7 +106,6 @@ class VideoReplyReplyController extends CommonController
@override
Future onRefresh() {
cursor = null;
isEnd = false;
return super.onRefresh();
}
@@ -159,24 +154,13 @@ class VideoReplyReplyController extends CommonController
}
}
if (isDialogue) {
if (replies.replies.isNotEmpty) {
if (replies.cursor.isEnd || replies.replies.length >= count.value) {
isEnd = true;
}
} else {
// 未登录状态replies可能返回null
isEnd = true;
}
isEnd = replies.replies.isEmpty ||
replies.cursor.isEnd ||
replies.replies.length >= count.value;
} else {
if (replies.root.replies.isNotEmpty) {
if (replies.cursor.isEnd ||
replies.root.replies.length >= count.value) {
isEnd = true;
}
} else {
// 未登录状态replies可能返回null
isEnd = true;
}
isEnd = replies.root.replies.isEmpty ||
replies.cursor.isEnd ||
replies.root.replies.length >= count.value;
}
if (isDialogue) {
loadingState.value = LoadingState.success(replies.replies);

View File

@@ -149,9 +149,9 @@ class _VideoReplyReplyPanelState extends State<VideoReplyReplyPanel> {
physics: const AlwaysScrollableScrollPhysics(),
itemBuilder: (_, index) {
if (widget.isDialogue) {
return Obx(() => _buildBody(
return _buildBody(
_videoReplyReplyController.loadingState.value,
index));
index);
} else if (firstFloor != null) {
if (index == 0) {
return ReplyItemGrpc(
@@ -176,17 +176,17 @@ class _VideoReplyReplyPanelState extends State<VideoReplyReplyPanel> {
} else if (index == 2) {
return _sortWidget;
} else {
return Obx(() => _buildBody(
return _buildBody(
_videoReplyReplyController.loadingState.value,
index - 3));
index - 3);
}
} else {
if (index == 0) {
return _sortWidget;
} else {
return Obx(() => _buildBody(
return _buildBody(
_videoReplyReplyController.loadingState.value,
index - 1));
index - 1);
}
}
},
@@ -285,6 +285,7 @@ class _VideoReplyReplyPanelState extends State<VideoReplyReplyPanel> {
?.response ??
<ReplyInfo>[];
list.insert(index + 1, replyInfo);
_videoReplyReplyController.count.value += 1;
_videoReplyReplyController.loadingState.value =
LoadingState.success(list);
}
@@ -314,22 +315,19 @@ class _VideoReplyReplyPanelState extends State<VideoReplyReplyPanel> {
_videoReplyReplyController.onLoadMore();
});
return Container(
alignment: Alignment.center,
padding: EdgeInsets.only(
bottom: MediaQuery.of(context).padding.bottom),
height: MediaQuery.of(context).padding.bottom + 100,
child: Center(
child: Obx(
() => Text(
_videoReplyReplyController.isEnd.not
? '加载中...'
: loadingState.response.isEmpty
? '还没有评论'
: '没有更多了',
style: TextStyle(
fontSize: 12,
color: Theme.of(context).colorScheme.outline,
),
),
child: Text(
_videoReplyReplyController.isEnd.not
? '加载中...'
: loadingState.response.isEmpty
? '还没有评论'
: '没有更多了',
style: TextStyle(
fontSize: 12,
color: Theme.of(context).colorScheme.outline,
),
),
);
@@ -376,6 +374,7 @@ class _VideoReplyReplyPanelState extends State<VideoReplyReplyPanel> {
List list =
(_videoReplyReplyController.loadingState.value as Success).response;
list = list.where((item) => item.id != rpid).toList();
_videoReplyReplyController.count.value -= 1;
_videoReplyReplyController.loadingState.value =
LoadingState.success(list);
},