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

This commit is contained in:
guozhigq
2024-04-26 23:22:26 +08:00
parent ac9a2349c0
commit 23e2e83636
6 changed files with 99 additions and 78 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

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

View File

@ -110,14 +110,15 @@ class _VideoReplyPanelState extends State<VideoReplyPanel>
} }
// 展示二级回复 // 展示二级回复
void replyReply(replyItem) { void replyReply(replyItem, currentReply) {
final VideoDetailController videoDetailCtr = final VideoDetailController videoDetailCtr =
Get.find<VideoDetailController>(tag: heroTag); Get.find<VideoDetailController>(tag: heroTag);
if (replyItem != null) { if (replyItem != null) {
videoDetailCtr.oid.value = replyItem.oid; videoDetailCtr.oid.value = replyItem.oid;
videoDetailCtr.fRpid = replyItem.rpid!; videoDetailCtr.fRpid = replyItem.rpid!;
videoDetailCtr.firstFloor = replyItem; videoDetailCtr.firstFloor = replyItem;
videoDetailCtr.showReplyReplyPanel(); videoDetailCtr.showReplyReplyPanel(
replyItem.oid, replyItem.rpid!, replyItem, currentReply);
} }
} }
@ -228,8 +229,8 @@ class _VideoReplyPanelState extends State<VideoReplyPanel>
.replyList[index], .replyList[index],
showReplyRow: true, showReplyRow: true,
replyLevel: replyLevel, replyLevel: replyLevel,
replyReply: (replyItem) => replyReply: (replyItem, currentReply) =>
replyReply(replyItem), replyReply(replyItem, currentReply),
replyType: ReplyType.video, replyType: ReplyType.video,
); );
} }

View File

@ -12,7 +12,6 @@ import 'package:pilipala/pages/preview/index.dart';
import 'package:pilipala/pages/video/detail/index.dart'; import 'package:pilipala/pages/video/detail/index.dart';
import 'package:pilipala/pages/video/detail/reply_new/index.dart'; import 'package:pilipala/pages/video/detail/reply_new/index.dart';
import 'package:pilipala/utils/feed_back.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/storage.dart';
import 'package:pilipala/utils/url_utils.dart'; import 'package:pilipala/utils/url_utils.dart';
import 'package:pilipala/utils/utils.dart'; import 'package:pilipala/utils/utils.dart';
@ -45,7 +44,7 @@ class ReplyItem extends StatelessWidget {
onTap: () { onTap: () {
feedBack(); feedBack();
if (replyReply != null) { if (replyReply != null) {
replyReply!(replyItem); replyReply!(replyItem, null);
} }
}, },
onLongPress: () { onLongPress: () {
@ -59,28 +58,23 @@ class ReplyItem extends StatelessWidget {
}, },
); );
}, },
child: Column( child: Container(
children: [ padding: const EdgeInsets.fromLTRB(12, 14, 8, 5),
Padding( decoration: BoxDecoration(
padding: const EdgeInsets.fromLTRB(12, 14, 8, 5), border: Border(
child: content(context), bottom: BorderSide(
), width: 1,
Divider( color:
indent: 55, Theme.of(context).colorScheme.onInverseSurface.withOpacity(0.5),
endIndent: 15, ))),
height: 0.3, child: content(context),
color: Theme.of(context)
.colorScheme
.onInverseSurface
.withOpacity(0.5),
)
],
), ),
), ),
); );
} }
Widget lfAvtar(BuildContext context, String heroTag) { Widget lfAvtar(BuildContext context, String heroTag) {
ColorScheme colorScheme = Theme.of(context).colorScheme;
return Stack( return Stack(
children: [ children: [
Hero( Hero(
@ -100,11 +94,11 @@ class ReplyItem extends StatelessWidget {
child: Container( child: Container(
decoration: BoxDecoration( decoration: BoxDecoration(
borderRadius: BorderRadius.circular(7), borderRadius: BorderRadius.circular(7),
color: Theme.of(context).colorScheme.background, color: colorScheme.background,
), ),
child: Icon( child: Icon(
Icons.offline_bolt, Icons.offline_bolt,
color: Theme.of(context).colorScheme.primary, color: colorScheme.primary,
size: 16, size: 16,
), ),
), ),
@ -117,7 +111,7 @@ class ReplyItem extends StatelessWidget {
child: Container( child: Container(
decoration: BoxDecoration( decoration: BoxDecoration(
borderRadius: BorderRadius.circular(7), borderRadius: BorderRadius.circular(7),
color: Theme.of(context).colorScheme.background, color: colorScheme.background,
), ),
child: Image.asset( child: Image.asset(
'assets/images/big-vip.png', 'assets/images/big-vip.png',
@ -131,6 +125,8 @@ class ReplyItem extends StatelessWidget {
Widget content(BuildContext context) { Widget content(BuildContext context) {
final String heroTag = Utils.makeHeroTag(replyItem!.mid); final String heroTag = Utils.makeHeroTag(replyItem!.mid);
ColorScheme colorScheme = Theme.of(context).colorScheme;
TextTheme textTheme = Theme.of(context).textTheme;
return Column( return Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[ children: <Widget>[
@ -160,16 +156,17 @@ class ReplyItem extends StatelessWidget {
style: TextStyle( style: TextStyle(
color: replyItem!.member!.vip!['vipStatus'] > 0 color: replyItem!.member!.vip!['vipStatus'] > 0
? const Color.fromARGB(255, 251, 100, 163) ? const Color.fromARGB(255, 251, 100, 163)
: Theme.of(context).colorScheme.outline, : colorScheme.outline,
fontSize: 13, fontSize: 13,
), ),
), ),
const SizedBox(width: 6), Padding(
Image.asset( padding: const EdgeInsets.only(left: 6, right: 6),
'assets/images/lv/lv${replyItem!.member!.level}.png', child: Image.asset(
height: 11, 'assets/images/lv/lv${replyItem!.member!.level}.png',
height: 11,
),
), ),
const SizedBox(width: 6),
if (replyItem!.isUp!) if (replyItem!.isUp!)
const PBadge( const PBadge(
text: 'UP', text: 'UP',
@ -184,9 +181,8 @@ class ReplyItem extends StatelessWidget {
Text( Text(
Utils.dateFormat(replyItem!.ctime), Utils.dateFormat(replyItem!.ctime),
style: TextStyle( style: TextStyle(
fontSize: fontSize: textTheme.labelSmall!.fontSize,
Theme.of(context).textTheme.labelSmall!.fontSize, color: colorScheme.outline,
color: Theme.of(context).colorScheme.outline,
), ),
), ),
if (replyItem!.replyControl != null && if (replyItem!.replyControl != null &&
@ -194,11 +190,8 @@ class ReplyItem extends StatelessWidget {
Text( Text(
'${replyItem!.replyControl!.location!}', '${replyItem!.replyControl!.location!}',
style: TextStyle( style: TextStyle(
fontSize: Theme.of(context) fontSize: textTheme.labelSmall!.fontSize,
.textTheme color: colorScheme.outline),
.labelSmall!
.fontSize,
color: Theme.of(context).colorScheme.outline),
), ),
], ],
) )
@ -256,6 +249,8 @@ class ReplyItem extends StatelessWidget {
// 感谢、回复、复制 // 感谢、回复、复制
Widget bottonAction(BuildContext context, replyControl) { Widget bottonAction(BuildContext context, replyControl) {
ColorScheme colorScheme = Theme.of(context).colorScheme;
TextTheme textTheme = Theme.of(context).textTheme;
return Row( return Row(
children: <Widget>[ children: <Widget>[
const SizedBox(width: 32), const SizedBox(width: 32),
@ -287,15 +282,13 @@ class ReplyItem extends StatelessWidget {
}, },
child: Row(children: [ child: Row(children: [
Icon(Icons.reply, Icon(Icons.reply,
size: 18, size: 18, color: colorScheme.outline.withOpacity(0.8)),
color:
Theme.of(context).colorScheme.outline.withOpacity(0.8)),
const SizedBox(width: 3), const SizedBox(width: 3),
Text( Text(
'回复', '回复',
style: TextStyle( style: TextStyle(
fontSize: Theme.of(context).textTheme.labelMedium!.fontSize, fontSize: textTheme.labelMedium!.fontSize,
color: Theme.of(context).colorScheme.outline, color: colorScheme.outline,
), ),
), ),
]), ]),
@ -306,8 +299,8 @@ class ReplyItem extends StatelessWidget {
Text( Text(
'up主觉得很赞', 'up主觉得很赞',
style: TextStyle( style: TextStyle(
color: Theme.of(context).colorScheme.primary, color: colorScheme.primary,
fontSize: Theme.of(context).textTheme.labelMedium!.fontSize), fontSize: textTheme.labelMedium!.fontSize),
), ),
const SizedBox(width: 2), const SizedBox(width: 2),
], ],
@ -316,8 +309,8 @@ class ReplyItem extends StatelessWidget {
Text( Text(
'热评', '热评',
style: TextStyle( style: TextStyle(
color: Theme.of(context).colorScheme.primary, color: colorScheme.primary,
fontSize: Theme.of(context).textTheme.labelMedium!.fontSize), fontSize: textTheme.labelMedium!.fontSize),
), ),
const Spacer(), const Spacer(),
ZanButton(replyItem: replyItem, replyType: replyType), ZanButton(replyItem: replyItem, replyType: replyType),
@ -347,10 +340,13 @@ class ReplyItemRow extends StatelessWidget {
Widget build(BuildContext context) { Widget build(BuildContext context) {
final bool isShow = replyControl!.isShow!; final bool isShow = replyControl!.isShow!;
final int extraRow = replyControl != null && isShow ? 1 : 0; final int extraRow = replyControl != null && isShow ? 1 : 0;
ColorScheme colorScheme = Theme.of(context).colorScheme;
TextTheme textTheme = Theme.of(context).textTheme;
return Container( return Container(
margin: const EdgeInsets.only(left: 42, right: 4, top: 0), margin: const EdgeInsets.only(left: 42, right: 4, top: 0),
child: Material( child: Material(
color: Theme.of(context).colorScheme.onInverseSurface, color: colorScheme.onInverseSurface,
borderRadius: BorderRadius.circular(6), borderRadius: BorderRadius.circular(6),
clipBehavior: Clip.hardEdge, clipBehavior: Clip.hardEdge,
animationDuration: Duration.zero, animationDuration: Duration.zero,
@ -361,7 +357,9 @@ class ReplyItemRow extends StatelessWidget {
for (int i = 0; i < replies!.length; i++) ...[ for (int i = 0; i < replies!.length; i++) ...[
InkWell( InkWell(
// 一楼点击评论展开评论详情 // 一楼点击评论展开评论详情
onTap: () => replyReply!(replyItem), // onTap: () {
// replyReply?.call(replyItem, replies![i]);
// },
onLongPress: () { onLongPress: () {
feedBack(); feedBack();
showModalBottomSheet( showModalBottomSheet(
@ -379,7 +377,7 @@ class ReplyItemRow extends StatelessWidget {
8, 8,
i == 0 && (extraRow == 1 || replies!.length > 1) ? 8 : 5, i == 0 && (extraRow == 1 || replies!.length > 1) ? 8 : 5,
8, 8,
i == 0 && (extraRow == 1 || replies!.length > 1) ? 5 : 6, 6,
), ),
child: Text.rich( child: Text.rich(
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
@ -393,7 +391,7 @@ class ReplyItemRow extends StatelessWidget {
.textTheme .textTheme
.titleSmall! .titleSmall!
.fontSize, .fontSize,
color: Theme.of(context).colorScheme.primary, color: colorScheme.primary,
), ),
recognizer: TapGestureRecognizer() recognizer: TapGestureRecognizer()
..onTap = () { ..onTap = () {
@ -429,15 +427,14 @@ class ReplyItemRow extends StatelessWidget {
if (extraRow == 1) if (extraRow == 1)
InkWell( InkWell(
// 一楼点击【共xx条回复】展开评论详情 // 一楼点击【共xx条回复】展开评论详情
onTap: () => replyReply!(replyItem), onTap: () => replyReply!(replyItem, null),
child: Container( child: Container(
width: double.infinity, width: double.infinity,
padding: const EdgeInsets.fromLTRB(8, 5, 8, 8), padding: const EdgeInsets.fromLTRB(8, 5, 8, 8),
child: Text.rich( child: Text.rich(
TextSpan( TextSpan(
style: TextStyle( style: TextStyle(
fontSize: fontSize: textTheme.labelMedium!.fontSize,
Theme.of(context).textTheme.labelMedium!.fontSize,
), ),
children: [ children: [
if (replyControl!.upReply!) if (replyControl!.upReply!)
@ -445,7 +442,7 @@ class ReplyItemRow extends StatelessWidget {
TextSpan( TextSpan(
text: replyControl!.entryText!, text: replyControl!.entryText!,
style: TextStyle( style: TextStyle(
color: Theme.of(context).colorScheme.primary, color: colorScheme.primary,
), ),
) )
], ],
@ -464,6 +461,7 @@ InlineSpan buildContent(
BuildContext context, replyItem, replyReply, fReplyItem) { BuildContext context, replyItem, replyReply, fReplyItem) {
final String routePath = Get.currentRoute; final String routePath = Get.currentRoute;
bool isVideoPage = routePath.startsWith('/video'); bool isVideoPage = routePath.startsWith('/video');
ColorScheme colorScheme = Theme.of(context).colorScheme;
// replyItem 当前回复内容 // replyItem 当前回复内容
// replyReply 查看二楼回复(回复详情)回调 // replyReply 查看二楼回复(回复详情)回调
@ -533,8 +531,10 @@ InlineSpan buildContent(
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,
),
), ),
); );
} }
@ -564,7 +564,7 @@ InlineSpan buildContent(
TextSpan( TextSpan(
text: matchStr, text: matchStr,
style: TextStyle( style: TextStyle(
color: Theme.of(context).colorScheme.primary, color: colorScheme.primary,
), ),
recognizer: TapGestureRecognizer() recognizer: TapGestureRecognizer()
..onTap = () { ..onTap = () {
@ -584,7 +584,7 @@ InlineSpan buildContent(
text: ' $matchStr ', text: ' $matchStr ',
style: isVideoPage style: isVideoPage
? TextStyle( ? TextStyle(
color: Theme.of(context).colorScheme.primary, color: colorScheme.primary,
) )
: null, : null,
recognizer: TapGestureRecognizer() recognizer: TapGestureRecognizer()
@ -624,14 +624,14 @@ InlineSpan buildContent(
child: Image.network( child: Image.network(
content.jumpUrl[matchStr]['prefix_icon'], content.jumpUrl[matchStr]['prefix_icon'],
height: 19, height: 19,
color: Theme.of(context).colorScheme.primary, color: colorScheme.primary,
), ),
) )
], ],
TextSpan( TextSpan(
text: content.jumpUrl[matchStr]['title'], text: content.jumpUrl[matchStr]['title'],
style: TextStyle( style: TextStyle(
color: Theme.of(context).colorScheme.primary, color: colorScheme.primary,
), ),
recognizer: TapGestureRecognizer() recognizer: TapGestureRecognizer()
..onTap = () async { ..onTap = () async {
@ -721,7 +721,7 @@ InlineSpan buildContent(
TextSpan( TextSpan(
text: matchStr, text: matchStr,
style: TextStyle( style: TextStyle(
color: Theme.of(context).colorScheme.primary, color: colorScheme.primary,
), ),
recognizer: TapGestureRecognizer() recognizer: TapGestureRecognizer()
..onTap = () { ..onTap = () {
@ -747,7 +747,7 @@ InlineSpan buildContent(
text: ' $matchStr ', text: ' $matchStr ',
style: isVideoPage style: isVideoPage
? TextStyle( ? TextStyle(
color: Theme.of(context).colorScheme.primary, color: colorScheme.primary,
) )
: null, : null,
recognizer: TapGestureRecognizer() recognizer: TapGestureRecognizer()
@ -786,14 +786,14 @@ InlineSpan buildContent(
child: Image.network( child: Image.network(
content.jumpUrl[patternStr]['prefix_icon'], content.jumpUrl[patternStr]['prefix_icon'],
height: 19, height: 19,
color: Theme.of(context).colorScheme.primary, color: colorScheme.primary,
), ),
) )
], ],
TextSpan( TextSpan(
text: content.jumpUrl[patternStr]['title'], text: content.jumpUrl[patternStr]['title'],
style: TextStyle( style: TextStyle(
color: Theme.of(context).colorScheme.primary, color: colorScheme.primary,
), ),
recognizer: TapGestureRecognizer() recognizer: TapGestureRecognizer()
..onTap = () { ..onTap = () {
@ -997,7 +997,8 @@ class MorePanel extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
Color errorColor = Theme.of(context).colorScheme.error; ColorScheme colorScheme = Theme.of(context).colorScheme;
TextTheme textTheme = Theme.of(context).textTheme;
return Container( return Container(
padding: EdgeInsets.only(bottom: MediaQuery.of(context).padding.bottom), padding: EdgeInsets.only(bottom: MediaQuery.of(context).padding.bottom),
child: Column( child: Column(
@ -1013,7 +1014,7 @@ class MorePanel extends StatelessWidget {
width: 32, width: 32,
height: 3, height: 3,
decoration: BoxDecoration( decoration: BoxDecoration(
color: Theme.of(context).colorScheme.outline, color: colorScheme.outline,
borderRadius: const BorderRadius.all(Radius.circular(3))), borderRadius: const BorderRadius.all(Radius.circular(3))),
), ),
), ),
@ -1023,13 +1024,13 @@ class MorePanel extends StatelessWidget {
onTap: () async => await menuActionHandler('copyAll'), onTap: () async => await menuActionHandler('copyAll'),
minLeadingWidth: 0, minLeadingWidth: 0,
leading: const Icon(Icons.copy_all_outlined, size: 19), leading: const Icon(Icons.copy_all_outlined, size: 19),
title: Text('复制全部', style: Theme.of(context).textTheme.titleSmall), title: Text('复制全部', style: textTheme.titleSmall),
), ),
ListTile( ListTile(
onTap: () async => await menuActionHandler('copyFreedom'), onTap: () async => await menuActionHandler('copyFreedom'),
minLeadingWidth: 0, minLeadingWidth: 0,
leading: const Icon(Icons.copy_outlined, size: 19), leading: const Icon(Icons.copy_outlined, size: 19),
title: Text('自由复制', style: Theme.of(context).textTheme.titleSmall), title: Text('自由复制', style: textTheme.titleSmall),
), ),
// ListTile( // ListTile(
// onTap: () async => await menuActionHandler('block'), // onTap: () async => await menuActionHandler('block'),

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,14 @@ 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);
}
}
isLoadingMore = false; isLoadingMore = false;
return res; return res;
} }

View File

@ -20,6 +20,7 @@ class VideoReplyReplyPanel extends StatefulWidget {
this.source, this.source,
this.replyType, this.replyType,
this.sheetHeight, this.sheetHeight,
this.currentReply,
super.key, super.key,
}); });
final int? oid; final int? oid;
@ -29,6 +30,7 @@ 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;
@override @override
State<VideoReplyReplyPanel> createState() => _VideoReplyReplyPanelState(); 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) {} void replyReply(replyItem) {}
@ -107,7 +111,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,
@ -140,6 +146,10 @@ class _VideoReplyReplyPanelState extends State<VideoReplyReplyPanel> {
if (snapshot.connectionState == ConnectionState.done) { if (snapshot.connectionState == ConnectionState.done) {
Map? data = snapshot.data; Map? data = snapshot.data;
if (data != null && data['status']) { if (data != null && data['status']) {
if (widget.currentReply != null) {
_videoReplyReplyController.replyList
.insert(0, widget.currentReply);
}
// 请求成功 // 请求成功
return Obx( return Obx(
() => SliverList( () => SliverList(