fix: 点赞异常、动态课程内容渲染

This commit is contained in:
guozhigq
2023-08-22 14:17:51 +08:00
parent b7c0ef8341
commit 6a1c89f885
5 changed files with 96 additions and 53 deletions

View File

@ -37,7 +37,7 @@ class _ActionPanelState extends State<ActionPanel> {
String dynamicId = item.idStr!;
// 1 已点赞 2 不喜欢 0 未操作
Like like = item.modules.moduleStat.like;
int count = int.parse(like.count!);
int count = like.count == '点赞' ? 0 : int.parse(like.count ?? '0');
bool status = like.status!;
int up = status ? 2 : 1;
var res = await DynamicsHttp.likeDynamic(dynamicId: dynamicId, up: up);
@ -47,7 +47,11 @@ class _ActionPanelState extends State<ActionPanel> {
item.modules.moduleStat.like.count = (count + 1).toString();
item.modules.moduleStat.like.status = true;
} else {
item.modules.moduleStat.like.count = (count - 1).toString();
if (count == 1) {
item.modules.moduleStat.like.count = '点赞';
} else {
item.modules.moduleStat.like.count = (count - 1).toString();
}
item.modules.moduleStat.like.status = false;
}
setState(() {});
@ -63,54 +67,63 @@ class _ActionPanelState extends State<ActionPanel> {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
TextButton.icon(
onPressed: () {},
icon: const Icon(
FontAwesomeIcons.shareFromSquare,
size: 16,
Expanded(
flex: 1,
child: TextButton.icon(
onPressed: () {},
icon: const Icon(
FontAwesomeIcons.shareFromSquare,
size: 16,
),
style: TextButton.styleFrom(
padding: const EdgeInsets.fromLTRB(15, 0, 15, 0),
foregroundColor: Theme.of(context).colorScheme.outline,
),
label: Text(stat.forward!.count ?? '转发'),
),
style: TextButton.styleFrom(
padding: const EdgeInsets.fromLTRB(15, 0, 15, 0),
foregroundColor: Theme.of(context).colorScheme.outline,
),
label: Text(stat.forward!.count ?? '转发'),
),
TextButton.icon(
onPressed: () =>
_dynamicsController.pushDetail(widget.item, 1, action: 'comment'),
icon: const Icon(
FontAwesomeIcons.comment,
size: 16,
Expanded(
flex: 1,
child: TextButton.icon(
onPressed: () => _dynamicsController.pushDetail(widget.item, 1,
action: 'comment'),
icon: const Icon(
FontAwesomeIcons.comment,
size: 16,
),
style: TextButton.styleFrom(
padding: const EdgeInsets.fromLTRB(15, 0, 15, 0),
foregroundColor: Theme.of(context).colorScheme.outline,
),
label: Text(stat.comment!.count ?? '评论'),
),
style: TextButton.styleFrom(
padding: const EdgeInsets.fromLTRB(15, 0, 15, 0),
foregroundColor: Theme.of(context).colorScheme.outline,
),
label: Text(stat.comment!.count ?? '评论'),
),
TextButton.icon(
onPressed: () => onLikeDynamic(),
icon: Icon(
stat.like!.status!
? FontAwesomeIcons.solidThumbsUp
: FontAwesomeIcons.thumbsUp,
size: 16,
color: stat.like!.status! ? primary : color,
),
style: TextButton.styleFrom(
padding: const EdgeInsets.fromLTRB(15, 0, 15, 0),
foregroundColor: Theme.of(context).colorScheme.outline,
),
label: AnimatedSwitcher(
duration: const Duration(milliseconds: 400),
transitionBuilder: (Widget child, Animation<double> animation) {
return ScaleTransition(scale: animation, child: child);
},
child: Text(
stat.like!.count ?? '点赞',
key: ValueKey<String>(stat.like!.count ?? '点赞'),
style: TextStyle(
color: stat.like!.status! ? primary : color,
Expanded(
flex: 1,
child: TextButton.icon(
onPressed: () => onLikeDynamic(),
icon: Icon(
stat.like!.status!
? FontAwesomeIcons.solidThumbsUp
: FontAwesomeIcons.thumbsUp,
size: 16,
color: stat.like!.status! ? primary : color,
),
style: TextButton.styleFrom(
padding: const EdgeInsets.fromLTRB(15, 0, 15, 0),
foregroundColor: Theme.of(context).colorScheme.outline,
),
label: AnimatedSwitcher(
duration: const Duration(milliseconds: 400),
transitionBuilder: (Widget child, Animation<double> animation) {
return ScaleTransition(scale: animation, child: child);
},
child: Text(
stat.like!.count ?? '点赞',
key: ValueKey<String>(stat.like!.count ?? '点赞'),
style: TextStyle(
color: stat.like!.status! ? primary : color,
),
),
),
),

View File

@ -100,6 +100,7 @@ Widget forWard(item, context, ctr, source, {floor = 1}) {
// 直播
case 'DYNAMIC_TYPE_LIVE_RCMD':
return liveRcmdPanel(item, context, floor: floor);
// 直播
case 'DYNAMIC_TYPE_LIVE':
return livePanel(item, context, floor: floor);
// 合集
@ -147,6 +148,7 @@ Widget forWard(item, context, ctr, source, {floor = 1}) {
return videoSeasonWidget(item, context, 'pgc', floor: floor);
case 'DYNAMIC_TYPE_PGC_UNION':
return videoSeasonWidget(item, context, 'pgc', floor: floor);
// 直播结束
case 'DYNAMIC_TYPE_NONE':
return Row(
children: [
@ -158,7 +160,23 @@ Widget forWard(item, context, ctr, source, {floor = 1}) {
Text(item.modules.moduleDynamic.major.none.tips)
],
);
// 课堂
case 'DYNAMIC_TYPE_COURSES_SEASON':
return Row(
children: [
Expanded(
child: Text(
"课堂💪:${item.modules.moduleDynamic.major.courses['title']}",
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
)
],
);
default:
return const SizedBox(height: 0);
return const SizedBox(
width: double.infinity,
child: Text('🙏 暂未支持的类型,请联系开发者反馈 '),
);
}
}