From 5ea636848799005ca832677fdd5c92f63865d9a4 Mon Sep 17 00:00:00 2001 From: bggRGjQaUbCoE Date: Sun, 6 Oct 2024 09:47:15 +0800 Subject: [PATCH] opt: action panel --- lib/pages/dynamics/widgets/action_panel.dart | 56 ++++++++++++++------ 1 file changed, 40 insertions(+), 16 deletions(-) diff --git a/lib/pages/dynamics/widgets/action_panel.dart b/lib/pages/dynamics/widgets/action_panel.dart index 27b6395f..82cfc6ed 100644 --- a/lib/pages/dynamics/widgets/action_panel.dart +++ b/lib/pages/dynamics/widgets/action_panel.dart @@ -26,7 +26,7 @@ class ActionPanel extends StatefulWidget { class _ActionPanelState extends State { final DynamicsController _dynamicsController = Get.put(DynamicsController()); - late ModuleStatModel stat; + // late ModuleStatModel stat; bool isProcessing = false; void Function()? handleState(Future Function() action) { return isProcessing @@ -38,11 +38,11 @@ class _ActionPanelState extends State { }; } - @override - void initState() { - super.initState(); - stat = widget.item!.modules.moduleStat; - } + // @override + // void initState() { + // super.initState(); + // stat = widget.item!.modules.moduleStat; + // } // 动态点赞 Future onLikeDynamic() async { @@ -89,7 +89,18 @@ class _ActionPanelState extends State { context: context, isScrollControlled: true, useSafeArea: true, - builder: (_) => RepostPanel(item: widget.item), + builder: (_) => RepostPanel( + item: widget.item, + callback: () { + int count = int.tryParse( + widget.item!.modules.moduleStat.forward?.count ?? + '0') ?? + 0; + widget.item!.modules.moduleStat.forward!.count = + (count + 1).toString(); + setState(() {}); + }, + ), ); }, icon: const Icon( @@ -101,7 +112,7 @@ class _ActionPanelState extends State { padding: const EdgeInsets.fromLTRB(15, 0, 15, 0), foregroundColor: Theme.of(context).colorScheme.outline, ), - label: Text(stat.forward!.count ?? ''), + label: Text(widget.item!.modules.moduleStat.forward!.count ?? '转发'), ), ), Expanded( @@ -118,7 +129,7 @@ class _ActionPanelState extends State { padding: const EdgeInsets.fromLTRB(15, 0, 15, 0), foregroundColor: Theme.of(context).colorScheme.outline, ), - label: Text(stat.comment!.count ?? ''), + label: Text(widget.item!.modules.moduleStat.comment!.count ?? '评论'), ), ), Expanded( @@ -126,12 +137,15 @@ class _ActionPanelState extends State { child: TextButton.icon( onPressed: handleState(onLikeDynamic), icon: Icon( - stat.like!.status! + widget.item!.modules.moduleStat.like!.status! ? FontAwesomeIcons.solidThumbsUp : FontAwesomeIcons.thumbsUp, size: 16, - color: stat.like!.status! ? primary : color, - semanticLabel: stat.like!.status! ? "已赞" : "点赞", + color: widget.item!.modules.moduleStat.like!.status! + ? primary + : color, + semanticLabel: + widget.item!.modules.moduleStat.like!.status! ? "已赞" : "点赞", ), style: TextButton.styleFrom( padding: const EdgeInsets.fromLTRB(15, 0, 15, 0), @@ -143,10 +157,13 @@ class _ActionPanelState extends State { return ScaleTransition(scale: animation, child: child); }, child: Text( - stat.like!.count ?? '', - key: ValueKey(stat.like!.count ?? '点赞'), + widget.item!.modules.moduleStat.like!.count ?? '点赞', + key: ValueKey( + widget.item!.modules.moduleStat.like!.count ?? '点赞'), style: TextStyle( - color: stat.like!.status! ? primary : color, + color: widget.item!.modules.moduleStat.like!.status! + ? primary + : color, ), ), ), @@ -158,9 +175,15 @@ class _ActionPanelState extends State { } class RepostPanel extends StatefulWidget { - const RepostPanel({super.key, required this.item}); + const RepostPanel({ + super.key, + required this.item, + required this.callback, + }); final dynamic item; + final Function callback; + @override State createState() => _RepostPanelState(); } @@ -180,6 +203,7 @@ class _RepostPanelState extends State { if (result['status']) { Get.back(); SmartDialog.showToast('转发成功'); + widget.callback(); } else { SmartDialog.showToast(result['msg']); }