From 6fa4f69af546ba69b724a549729fa2374aed5a68 Mon Sep 17 00:00:00 2001 From: orz12 Date: Thu, 21 Dec 2023 21:06:35 +0800 Subject: [PATCH 1/3] =?UTF-8?q?opt:=20=E7=A7=BB=E9=99=A4=E5=9B=9E=E5=A4=8D?= =?UTF-8?q?=E7=82=B9=E8=B5=9E=E5=86=97=E4=BD=99=E5=8A=A0=E8=BD=BD=E6=8F=90?= =?UTF-8?q?=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/pages/video/detail/reply/widgets/zan.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/pages/video/detail/reply/widgets/zan.dart b/lib/pages/video/detail/reply/widgets/zan.dart index da0c1378..c628904f 100644 --- a/lib/pages/video/detail/reply/widgets/zan.dart +++ b/lib/pages/video/detail/reply/widgets/zan.dart @@ -24,7 +24,7 @@ class _ZanButtonState extends State { // 评论点赞 onLikeReply() async { feedBack(); - SmartDialog.showLoading(msg: 'pilipala ...'); + // SmartDialog.showLoading(msg: 'pilipala ...'); ReplyItemModel replyItem = widget.replyItem!; int oid = replyItem.oid!; int rpid = replyItem.rpid!; @@ -32,7 +32,7 @@ class _ZanButtonState extends State { int action = replyItem.action == 0 ? 1 : 0; var res = await ReplyHttp.likeReply( type: widget.replyType!.index, oid: oid, rpid: rpid, action: action); - SmartDialog.dismiss(); + // SmartDialog.dismiss(); if (res['status']) { SmartDialog.showToast(replyItem.action == 0 ? '点赞成功 👍' : '取消赞 💔'); if (action == 1) { From 0cf707b4c59f60fda6af075d6fee64c751d4e70a Mon Sep 17 00:00:00 2001 From: orz12 Date: Fri, 22 Dec 2023 11:03:06 +0800 Subject: [PATCH 2/3] =?UTF-8?q?opt:=20=E4=B8=BA=E6=89=80=E6=9C=89=E7=82=B9?= =?UTF-8?q?=E8=B5=9E=E3=80=81=E6=8A=95=E5=B8=81=E6=B7=BB=E5=8A=A0=E7=A6=81?= =?UTF-8?q?=E7=94=A8=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/pages/bangumi/introduction/view.dart | 19 ++++++++++++++----- lib/pages/dynamics/widgets/action_panel.dart | 15 ++++++++++++--- lib/pages/video/detail/introduction/view.dart | 19 ++++++++++++++----- lib/pages/video/detail/reply/widgets/zan.dart | 14 ++++++++++++-- 4 files changed, 52 insertions(+), 15 deletions(-) diff --git a/lib/pages/bangumi/introduction/view.dart b/lib/pages/bangumi/introduction/view.dart index 62842075..583be7d9 100644 --- a/lib/pages/bangumi/introduction/view.dart +++ b/lib/pages/bangumi/introduction/view.dart @@ -121,7 +121,16 @@ class _BangumiInfoState extends State { late final BangumiInfoModel? bangumiItem; late double sheetHeight; int? cid; - + bool isProcessing = false; + VoidCallback handleState(Future Function() action) { + return () async { + if (!isProcessing) { + setState(() => isProcessing = true); + await action(); + setState(() => isProcessing = false); + } + }; + } @override void initState() { super.initState(); @@ -395,7 +404,7 @@ class _BangumiInfoState extends State { () => ActionItem( icon: const Icon(FontAwesomeIcons.thumbsUp), selectIcon: const Icon(FontAwesomeIcons.solidThumbsUp), - onTap: () => bangumiIntroController.actionLikeVideo(), + onTap: handleState(bangumiIntroController.actionLikeVideo), selectStatus: bangumiIntroController.hasLike.value, loadingStatus: false, text: !widget.loadingStatus @@ -406,7 +415,7 @@ class _BangumiInfoState extends State { () => ActionItem( icon: const Icon(FontAwesomeIcons.b), selectIcon: const Icon(FontAwesomeIcons.b), - onTap: () => bangumiIntroController.actionCoinVideo(), + onTap: handleState(bangumiIntroController.actionCoinVideo), selectStatus: bangumiIntroController.hasCoin.value, loadingStatus: false, text: !widget.loadingStatus @@ -455,7 +464,7 @@ class _BangumiInfoState extends State { Obx( () => ActionRowItem( icon: const Icon(FontAwesomeIcons.thumbsUp), - onTap: () => videoIntroController.actionLikeVideo(), + onTap: handleState(videoIntroController.actionLikeVideo), selectStatus: videoIntroController.hasLike.value, loadingStatus: widget.loadingStatus, text: !widget.loadingStatus @@ -467,7 +476,7 @@ class _BangumiInfoState extends State { Obx( () => ActionRowItem( icon: const Icon(FontAwesomeIcons.b), - onTap: () => videoIntroController.actionCoinVideo(), + onTap: handleState(videoIntroController.actionCoinVideo), selectStatus: videoIntroController.hasCoin.value, loadingStatus: widget.loadingStatus, text: !widget.loadingStatus diff --git a/lib/pages/dynamics/widgets/action_panel.dart b/lib/pages/dynamics/widgets/action_panel.dart index 53c9e497..46ab7202 100644 --- a/lib/pages/dynamics/widgets/action_panel.dart +++ b/lib/pages/dynamics/widgets/action_panel.dart @@ -23,7 +23,16 @@ class ActionPanel extends StatefulWidget { class _ActionPanelState extends State { final DynamicsController _dynamicsController = Get.put(DynamicsController()); late ModuleStatModel stat; - + bool isProcessing = false; + VoidCallback handleState(Future Function() action) { + return () async { + if (!isProcessing) { + setState(() => isProcessing = true); + await action(); + setState(() => isProcessing = false); + } + }; + } @override void initState() { super.initState(); @@ -31,7 +40,7 @@ class _ActionPanelState extends State { } // 动态点赞 - onLikeDynamic() async { + Future onLikeDynamic() async { feedBack(); var item = widget.item!; String dynamicId = item.idStr!; @@ -101,7 +110,7 @@ class _ActionPanelState extends State { Expanded( flex: 1, child: TextButton.icon( - onPressed: () => onLikeDynamic(), + onPressed: handleState(onLikeDynamic), icon: Icon( stat.like!.status! ? FontAwesomeIcons.solidThumbsUp diff --git a/lib/pages/video/detail/introduction/view.dart b/lib/pages/video/detail/introduction/view.dart index 98ce9ba8..424ac509 100644 --- a/lib/pages/video/detail/introduction/view.dart +++ b/lib/pages/video/detail/introduction/view.dart @@ -134,7 +134,16 @@ class _VideoInfoState extends State with TickerProviderStateMixin { late int mid; late String memberHeroTag; late bool enableAi; - + bool isProcessing = false; + VoidCallback handleState(Future Function() action) { + return () async { + if (!isProcessing) { + setState(() => isProcessing = true); + await action(); + setState(() => isProcessing = false); + } + }; + } @override void initState() { super.initState(); @@ -477,7 +486,7 @@ class _VideoInfoState extends State with TickerProviderStateMixin { () => ActionItem( icon: const Icon(FontAwesomeIcons.thumbsUp), selectIcon: const Icon(FontAwesomeIcons.solidThumbsUp), - onTap: () => videoIntroController.actionLikeVideo(), + onTap: handleState(videoIntroController.actionLikeVideo), selectStatus: videoIntroController.hasLike.value, loadingStatus: loadingStatus, text: !loadingStatus @@ -494,7 +503,7 @@ class _VideoInfoState extends State with TickerProviderStateMixin { () => ActionItem( icon: const Icon(FontAwesomeIcons.b), selectIcon: const Icon(FontAwesomeIcons.b), - onTap: () => videoIntroController.actionCoinVideo(), + onTap: handleState(videoIntroController.actionCoinVideo), selectStatus: videoIntroController.hasCoin.value, loadingStatus: loadingStatus, text: !loadingStatus @@ -538,7 +547,7 @@ class _VideoInfoState extends State with TickerProviderStateMixin { Obx( () => ActionRowItem( icon: const Icon(FontAwesomeIcons.thumbsUp), - onTap: () => videoIntroController.actionLikeVideo(), + onTap: handleState(videoIntroController.actionLikeVideo), selectStatus: videoIntroController.hasLike.value, loadingStatus: loadingStatus, text: @@ -549,7 +558,7 @@ class _VideoInfoState extends State with TickerProviderStateMixin { Obx( () => ActionRowItem( icon: const Icon(FontAwesomeIcons.b), - onTap: () => videoIntroController.actionCoinVideo(), + onTap: handleState(videoIntroController.actionCoinVideo), selectStatus: videoIntroController.hasCoin.value, loadingStatus: loadingStatus, text: diff --git a/lib/pages/video/detail/reply/widgets/zan.dart b/lib/pages/video/detail/reply/widgets/zan.dart index c628904f..6ce732dd 100644 --- a/lib/pages/video/detail/reply/widgets/zan.dart +++ b/lib/pages/video/detail/reply/widgets/zan.dart @@ -22,7 +22,7 @@ class ZanButton extends StatefulWidget { class _ZanButtonState extends State { // 评论点赞 - onLikeReply() async { + Future onLikeReply() async { feedBack(); // SmartDialog.showLoading(msg: 'pilipala ...'); ReplyItemModel replyItem = widget.replyItem!; @@ -47,6 +47,16 @@ class _ZanButtonState extends State { SmartDialog.showToast(res['msg']); } } + bool isProcessing = false; + VoidCallback handleState(Future Function() action) { + return () async { + if (!isProcessing) { + setState(() => isProcessing = true); + await action(); + setState(() => isProcessing = false); + } + }; + } @override Widget build(BuildContext context) { @@ -55,6 +65,7 @@ class _ZanButtonState extends State { return SizedBox( height: 32, child: TextButton( + onPressed: handleState(onLikeReply), child: Row( children: [ Icon( @@ -79,7 +90,6 @@ class _ZanButtonState extends State { ), ], ), - onPressed: () => onLikeReply(), ), ); } From 25d32f8cc88fb9e762f56cc64671f403d6c57aa4 Mon Sep 17 00:00:00 2001 From: orz12 Date: Sat, 23 Dec 2023 15:49:04 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E6=94=B9=E4=B8=BAnull=E7=9A=84=E5=BD=A2?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/pages/bangumi/introduction/view.dart | 12 +++++------- lib/pages/dynamics/widgets/action_panel.dart | 12 +++++------- lib/pages/video/detail/introduction/view.dart | 14 +++++++------- lib/pages/video/detail/reply/widgets/zan.dart | 12 +++++------- 4 files changed, 22 insertions(+), 28 deletions(-) diff --git a/lib/pages/bangumi/introduction/view.dart b/lib/pages/bangumi/introduction/view.dart index 583be7d9..63c66515 100644 --- a/lib/pages/bangumi/introduction/view.dart +++ b/lib/pages/bangumi/introduction/view.dart @@ -122,13 +122,11 @@ class _BangumiInfoState extends State { late double sheetHeight; int? cid; bool isProcessing = false; - VoidCallback handleState(Future Function() action) { - return () async { - if (!isProcessing) { - setState(() => isProcessing = true); - await action(); - setState(() => isProcessing = false); - } + void Function()? handleState(Future Function() action) { + return isProcessing ? null : () async { + setState(() => isProcessing = true); + await action(); + setState(() => isProcessing = false); }; } @override diff --git a/lib/pages/dynamics/widgets/action_panel.dart b/lib/pages/dynamics/widgets/action_panel.dart index 46ab7202..0ca09b8c 100644 --- a/lib/pages/dynamics/widgets/action_panel.dart +++ b/lib/pages/dynamics/widgets/action_panel.dart @@ -24,13 +24,11 @@ class _ActionPanelState extends State { final DynamicsController _dynamicsController = Get.put(DynamicsController()); late ModuleStatModel stat; bool isProcessing = false; - VoidCallback handleState(Future Function() action) { - return () async { - if (!isProcessing) { - setState(() => isProcessing = true); - await action(); - setState(() => isProcessing = false); - } + void Function()? handleState(Future Function() action) { + return isProcessing ? null : () async { + setState(() => isProcessing = true); + await action(); + setState(() => isProcessing = false); }; } @override diff --git a/lib/pages/video/detail/introduction/view.dart b/lib/pages/video/detail/introduction/view.dart index 424ac509..a0d4adde 100644 --- a/lib/pages/video/detail/introduction/view.dart +++ b/lib/pages/video/detail/introduction/view.dart @@ -1,3 +1,5 @@ +import 'dart:io'; + import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:get/get.dart'; @@ -135,13 +137,11 @@ class _VideoInfoState extends State with TickerProviderStateMixin { late String memberHeroTag; late bool enableAi; bool isProcessing = false; - VoidCallback handleState(Future Function() action) { - return () async { - if (!isProcessing) { - setState(() => isProcessing = true); - await action(); - setState(() => isProcessing = false); - } + void Function()? handleState(Future Function() action) { + return isProcessing ? null : () async { + setState(() => isProcessing = true); + await action(); + setState(() => isProcessing = false); }; } @override diff --git a/lib/pages/video/detail/reply/widgets/zan.dart b/lib/pages/video/detail/reply/widgets/zan.dart index 6ce732dd..b9ead14e 100644 --- a/lib/pages/video/detail/reply/widgets/zan.dart +++ b/lib/pages/video/detail/reply/widgets/zan.dart @@ -48,13 +48,11 @@ class _ZanButtonState extends State { } } bool isProcessing = false; - VoidCallback handleState(Future Function() action) { - return () async { - if (!isProcessing) { - setState(() => isProcessing = true); - await action(); - setState(() => isProcessing = false); - } + void Function()? handleState(Future Function() action) { + return isProcessing ? null : () async { + setState(() => isProcessing = true); + await action(); + setState(() => isProcessing = false); }; }