feat: 评论二楼跳转

This commit is contained in:
guozhigq
2024-07-21 22:40:43 +08:00
parent 9afecbecdb
commit a57f10ccdb
5 changed files with 132 additions and 86 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

@ -175,6 +175,8 @@ class VideoDetailController extends GetxController
replyType: ReplyType.video,
source: 'videoDetail',
sheetHeight: sheetHeight.value,
currentReply: currentReply,
loadMore: loadMore,
);
});
replyReplyBottomSheetCtr?.closed.then((value) {

View File

@ -49,7 +49,7 @@ class ReplyItem extends StatelessWidget {
onTap: () {
feedBack();
if (replyReply != null) {
replyReply!(replyItem);
replyReply!(replyItem, null, replyItem!.replies!.isNotEmpty);
}
},
onLongPress: () {
@ -362,9 +362,13 @@ class ReplyItemRow extends StatelessWidget {
for (int i = 0; i < replies!.length; i++) ...[
InkWell(
// 一楼点击评论展开评论详情
// onTap: () {
// replyReply?.call(replyItem);
// },
onTap: () {
replyReply?.call(
replyItem,
replies![i],
replyItem!.replies!.isNotEmpty,
);
},
onLongPress: () {
feedBack();
showModalBottomSheet(
@ -535,9 +539,12 @@ InlineSpan buildContent(
spanChilds.add(
TextSpan(
text: str,
recognizer: TapGestureRecognizer()
..onTap = () =>
replyReply?.call(replyItem.root == 0 ? replyItem : fReplyItem),
// recognizer: TapGestureRecognizer()
// ..onTap = () => replyReply?.call(
// replyItem.root == 0 ? replyItem : fReplyItem,
// replyItem,
// fReplyItem!.replies!.isNotEmpty,
// ),
),
);
}

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,17 @@ 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);
}
if (currentPage == 1 && type == 'init') {
replyList.insert(0, currentReply);
}
}
isLoadingMore = false;
return res;
}

View File

@ -20,6 +20,8 @@ class VideoReplyReplyPanel extends StatefulWidget {
this.source,
this.replyType,
this.sheetHeight,
this.currentReply,
this.loadMore,
super.key,
});
final int? oid;
@ -29,6 +31,8 @@ class VideoReplyReplyPanel extends StatefulWidget {
final String? source;
final ReplyType? replyType;
final double? sheetHeight;
final dynamic currentReply;
final bool? loadMore;
@override
State<VideoReplyReplyPanel> createState() => _VideoReplyReplyPanelState();
@ -63,7 +67,9 @@ class _VideoReplyReplyPanelState extends State<VideoReplyReplyPanel> {
},
);
_futureBuilderFuture = _videoReplyReplyController.queryReplyList();
_futureBuilderFuture = _videoReplyReplyController.queryReplyList(
currentReply: widget.currentReply,
);
}
void replyReply(replyItem) {}
@ -107,7 +113,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,
@ -134,10 +142,12 @@ class _VideoReplyReplyPanelState extends State<VideoReplyReplyPanel> {
),
),
],
FutureBuilder(
widget.loadMore != null && widget.loadMore!
? FutureBuilder(
future: _futureBuilderFuture,
builder: (BuildContext context, snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
if (snapshot.connectionState ==
ConnectionState.done) {
Map? data = snapshot.data;
if (data != null && data['status']) {
// 请求成功
@ -174,12 +184,14 @@ class _VideoReplyReplyPanelState extends State<VideoReplyReplyPanel> {
);
} else {
return ReplyItem(
replyItem: _videoReplyReplyController
replyItem:
_videoReplyReplyController
.replyList[index],
replyLevel: '2',
showReplyRow: false,
addReply: (replyItem) {
_videoReplyReplyController.replyList
_videoReplyReplyController
.replyList
.add(replyItem);
},
replyType: widget.replyType,
@ -212,6 +224,20 @@ class _VideoReplyReplyPanelState extends State<VideoReplyReplyPanel> {
}
},
)
: SliverToBoxAdapter(
child: SizedBox(
height: 200,
child: Center(
child: Text(
'还没有评论',
style: TextStyle(
fontSize: 12,
color: Theme.of(context).colorScheme.outline,
),
),
),
),
)
],
),
),