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 oid = replyItem.oid;
int rpid = replyItem.rpid!; int rpid = replyItem.rpid!;
Get.to( Get.to(
@ -324,8 +324,8 @@ class _DynamicDetailPageState extends State<DynamicDetailPage>
replyItem: replyList[index], replyItem: replyList[index],
showReplyRow: true, showReplyRow: true,
replyLevel: '1', replyLevel: '1',
replyReply: (replyItem) => replyReply: (replyItem, currentReply) =>
replyReply(replyItem), replyReply(replyItem, currentReply),
replyType: ReplyType.values[replyType], replyType: ReplyType.values[replyType],
addReply: (replyItem) { addReply: (replyItem) {
replyList[index] replyList[index]

View File

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

View File

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

View File

@ -26,7 +26,7 @@ class VideoReplyReplyController extends GetxController {
currentPage = 0; currentPage = 0;
} }
Future queryReplyList({type = 'init'}) async { Future queryReplyList({type = 'init', currentReply}) async {
if (type == 'init') { if (type == 'init') {
currentPage = 0; currentPage = 0;
} }
@ -63,6 +63,17 @@ class VideoReplyReplyController extends GetxController {
// res['data'].replies.addAll(replyList); // 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; isLoadingMore = false;
return res; return res;
} }

View File

@ -20,6 +20,8 @@ class VideoReplyReplyPanel extends StatefulWidget {
this.source, this.source,
this.replyType, this.replyType,
this.sheetHeight, this.sheetHeight,
this.currentReply,
this.loadMore,
super.key, super.key,
}); });
final int? oid; final int? oid;
@ -29,6 +31,8 @@ class VideoReplyReplyPanel extends StatefulWidget {
final String? source; final String? source;
final ReplyType? replyType; final ReplyType? replyType;
final double? sheetHeight; final double? sheetHeight;
final dynamic currentReply;
final bool? loadMore;
@override @override
State<VideoReplyReplyPanel> createState() => _VideoReplyReplyPanelState(); 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) {} void replyReply(replyItem) {}
@ -107,7 +113,9 @@ class _VideoReplyReplyPanelState extends State<VideoReplyReplyPanel> {
onRefresh: () async { onRefresh: () async {
setState(() {}); setState(() {});
_videoReplyReplyController.currentPage = 0; _videoReplyReplyController.currentPage = 0;
return await _videoReplyReplyController.queryReplyList(); return await _videoReplyReplyController.queryReplyList(
currentReply: widget.currentReply,
);
}, },
child: CustomScrollView( child: CustomScrollView(
controller: _videoReplyReplyController.scrollController, controller: _videoReplyReplyController.scrollController,
@ -134,84 +142,102 @@ class _VideoReplyReplyPanelState extends State<VideoReplyReplyPanel> {
), ),
), ),
], ],
FutureBuilder( widget.loadMore != null && widget.loadMore!
future: _futureBuilderFuture, ? FutureBuilder(
builder: (BuildContext context, snapshot) { future: _futureBuilderFuture,
if (snapshot.connectionState == ConnectionState.done) { builder: (BuildContext context, snapshot) {
Map? data = snapshot.data; if (snapshot.connectionState ==
if (data != null && data['status']) { ConnectionState.done) {
// 请求成功 Map? data = snapshot.data;
return Obx( if (data != null && data['status']) {
() => SliverList( // 请求成功
delegate: SliverChildBuilderDelegate( return Obx(
(BuildContext context, int index) { () => SliverList(
if (index == delegate: SliverChildBuilderDelegate(
_videoReplyReplyController (BuildContext context, int index) {
.replyList.length) { if (index ==
return Container(
padding: EdgeInsets.only(
bottom: MediaQuery.of(context)
.padding
.bottom),
height: MediaQuery.of(context)
.padding
.bottom +
100,
child: Center(
child: Obx(
() => Text(
_videoReplyReplyController _videoReplyReplyController
.noMore.value, .replyList.length) {
style: TextStyle( return Container(
fontSize: 12, padding: EdgeInsets.only(
color: Theme.of(context) bottom: MediaQuery.of(context)
.colorScheme .padding
.outline, .bottom),
height: MediaQuery.of(context)
.padding
.bottom +
100,
child: Center(
child: Obx(
() => Text(
_videoReplyReplyController
.noMore.value,
style: TextStyle(
fontSize: 12,
color: Theme.of(context)
.colorScheme
.outline,
),
),
),
), ),
), );
), } else {
), return ReplyItem(
); replyItem:
} else { _videoReplyReplyController
return ReplyItem( .replyList[index],
replyItem: _videoReplyReplyController replyLevel: '2',
.replyList[index], showReplyRow: false,
replyLevel: '2', addReply: (replyItem) {
showReplyRow: false, _videoReplyReplyController
addReply: (replyItem) { .replyList
_videoReplyReplyController.replyList .add(replyItem);
.add(replyItem); },
replyType: widget.replyType,
replyReply: (replyItem) =>
replyReply(replyItem),
);
}
}, },
replyType: widget.replyType, childCount: _videoReplyReplyController
replyReply: (replyItem) => .replyList.length +
replyReply(replyItem), 1,
); ),
} ),
}, );
childCount: _videoReplyReplyController } else {
.replyList.length + // 请求错误
1, return HttpError(
errMsg: data?['msg'] ?? '请求错误',
fn: () => setState(() {}),
);
}
} else {
// 骨架屏
return SliverList(
delegate: SliverChildBuilderDelegate(
(BuildContext context, int index) {
return const VideoReplySkeleton();
}, childCount: 8),
);
}
},
)
: SliverToBoxAdapter(
child: SizedBox(
height: 200,
child: Center(
child: Text(
'还没有评论',
style: TextStyle(
fontSize: 12,
color: Theme.of(context).colorScheme.outline,
),
), ),
), ),
); ),
} else { )
// 请求错误
return HttpError(
errMsg: data?['msg'] ?? '请求错误',
fn: () => setState(() {}),
);
}
} else {
// 骨架屏
return SliverList(
delegate: SliverChildBuilderDelegate(
(BuildContext context, int index) {
return const VideoReplySkeleton();
}, childCount: 8),
);
}
},
)
], ],
), ),
), ),