opt: 评论详情优先展示二级评论

This commit is contained in:
guozhigq
2024-04-26 23:22:26 +08:00
parent a60e307273
commit 72ee515ae5
6 changed files with 35 additions and 15 deletions

View File

@ -106,7 +106,7 @@ class _DynamicDetailPageState extends State<DynamicDetailPage>
}
// 查看二级评论
void replyReply(replyItem) {
void replyReply(replyItem, currentReply) {
int oid = replyItem.oid;
int rpid = replyItem.rpid!;
Get.to(
@ -324,8 +324,8 @@ class _DynamicDetailPageState extends State<DynamicDetailPage>
replyItem: replyList[index],
showReplyRow: true,
replyLevel: '1',
replyReply: (replyItem) =>
replyReply(replyItem),
replyReply: (replyItem, currentReply) =>
replyReply(replyItem, currentReply),
replyType: ReplyType.values[replyType],
addReply: (replyItem) {
replyList[index]

View File

@ -161,7 +161,7 @@ class VideoDetailController extends GetxController
getSubtitle();
}
showReplyReplyPanel(oid, fRpid, firstFloor) {
showReplyReplyPanel(oid, fRpid, firstFloor, currentReply, loadMore) {
replyReplyBottomSheetCtr =
scaffoldKey.currentState?.showBottomSheet((BuildContext context) {
return VideoReplyReplyPanel(
@ -174,6 +174,7 @@ class VideoDetailController extends GetxController
replyType: ReplyType.video,
source: 'videoDetail',
sheetHeight: sheetHeight.value,
currentReply: currentReply,
);
});
replyReplyBottomSheetCtr?.closed.then((value) {

View File

@ -112,7 +112,7 @@ class _VideoReplyPanelState extends State<VideoReplyPanel>
}
// 展示二级回复
void replyReply(replyItem) {
void replyReply(replyItem, currentReply) {
final VideoDetailController videoDetailCtr =
Get.find<VideoDetailController>(tag: heroTag);
if (replyItem != null) {
@ -232,8 +232,8 @@ class _VideoReplyPanelState extends State<VideoReplyPanel>
.replyList[index],
showReplyRow: true,
replyLevel: replyLevel,
replyReply: (replyItem) =>
replyReply(replyItem),
replyReply: (replyItem, currentReply) =>
replyReply(replyItem, currentReply),
replyType: ReplyType.video,
);
}

View File

@ -14,7 +14,6 @@ import 'package:pilipala/pages/video/detail/index.dart';
import 'package:pilipala/pages/video/detail/reply_new/index.dart';
import 'package:pilipala/utils/app_scheme.dart';
import 'package:pilipala/utils/feed_back.dart';
import 'package:pilipala/utils/id_utils.dart';
import 'package:pilipala/utils/storage.dart';
import 'package:pilipala/utils/url_utils.dart';
import 'package:pilipala/utils/utils.dart';
@ -47,7 +46,7 @@ class ReplyItem extends StatelessWidget {
onTap: () {
feedBack();
if (replyReply != null) {
replyReply!(replyItem);
replyReply!(replyItem, null);
}
},
onLongPress: () {
@ -430,7 +429,7 @@ class ReplyItemRow extends StatelessWidget {
if (extraRow == 1)
InkWell(
// 一楼点击【共xx条回复】展开评论详情
onTap: () => replyReply!(replyItem),
onTap: () => replyReply!(replyItem, null),
child: Container(
width: double.infinity,
padding: const EdgeInsets.fromLTRB(8, 5, 8, 8),
@ -534,8 +533,10 @@ InlineSpan buildContent(
TextSpan(
text: str,
recognizer: TapGestureRecognizer()
..onTap = () =>
replyReply?.call(replyItem.root == 0 ? replyItem : fReplyItem),
..onTap = () => replyReply?.call(
replyItem.root == 0 ? replyItem : fReplyItem,
replyItem,
),
),
);
}

View File

@ -26,7 +26,7 @@ class VideoReplyReplyController extends GetxController {
currentPage = 0;
}
Future queryReplyList({type = 'init'}) async {
Future queryReplyList({type = 'init', currentReply}) async {
if (type == 'init') {
currentPage = 0;
}
@ -63,6 +63,14 @@ class VideoReplyReplyController extends GetxController {
// res['data'].replies.addAll(replyList);
}
}
if (replyList.isNotEmpty && currentReply != null) {
int indexToRemove =
replyList.indexWhere((item) => currentReply.rpid == item.rpid);
// 如果找到了指定ID的项则移除
if (indexToRemove != -1) {
replyList.removeAt(indexToRemove);
}
}
isLoadingMore = false;
return res;
}

View File

@ -20,6 +20,7 @@ class VideoReplyReplyPanel extends StatefulWidget {
this.source,
this.replyType,
this.sheetHeight,
this.currentReply,
super.key,
});
final int? oid;
@ -29,6 +30,7 @@ class VideoReplyReplyPanel extends StatefulWidget {
final String? source;
final ReplyType? replyType;
final double? sheetHeight;
final dynamic currentReply;
@override
State<VideoReplyReplyPanel> createState() => _VideoReplyReplyPanelState();
@ -63,7 +65,9 @@ class _VideoReplyReplyPanelState extends State<VideoReplyReplyPanel> {
},
);
_futureBuilderFuture = _videoReplyReplyController.queryReplyList();
_futureBuilderFuture = _videoReplyReplyController.queryReplyList(
currentReply: widget.currentReply,
);
}
void replyReply(replyItem) {}
@ -107,7 +111,9 @@ class _VideoReplyReplyPanelState extends State<VideoReplyReplyPanel> {
onRefresh: () async {
setState(() {});
_videoReplyReplyController.currentPage = 0;
return await _videoReplyReplyController.queryReplyList();
return await _videoReplyReplyController.queryReplyList(
currentReply: widget.currentReply,
);
},
child: CustomScrollView(
controller: _videoReplyReplyController.scrollController,
@ -140,6 +146,10 @@ class _VideoReplyReplyPanelState extends State<VideoReplyReplyPanel> {
if (snapshot.connectionState == ConnectionState.done) {
Map? data = snapshot.data;
if (data != null && data['status']) {
if (widget.currentReply != null) {
_videoReplyReplyController.replyList
.insert(0, widget.currentReply);
}
// 请求成功
return Obx(
() => SliverList(