diff --git a/lib/pages/bangumi/introduction/view.dart b/lib/pages/bangumi/introduction/view.dart index 84bbbc3be..5f6582593 100644 --- a/lib/pages/bangumi/introduction/view.dart +++ b/lib/pages/bangumi/introduction/view.dart @@ -2,6 +2,7 @@ import 'dart:async'; import 'package:PiliPalaX/common/widgets/http_error.dart'; import 'package:PiliPalaX/http/loading_state.dart'; +import 'package:PiliPalaX/utils/extension.dart'; import 'package:flutter/material.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; @@ -136,14 +137,12 @@ class _BangumiInfoState extends State late final BangumiInfoModel? bangumiItem; int? cid; bool isProcessing = false; - void Function()? handleState(Future Function() action) { - return isProcessing - ? null - : () async { - setState(() => isProcessing = true); - await action(); - setState(() => isProcessing = false); - }; + void handleState(Future Function() action) async { + if (isProcessing.not) { + isProcessing = true; + await action(); + isProcessing = false; + } } late final _coinKey = GlobalKey(); @@ -447,7 +446,8 @@ class _BangumiInfoState extends State () => ActionItem( icon: const Icon(FontAwesomeIcons.thumbsUp), selectIcon: const Icon(FontAwesomeIcons.solidThumbsUp), - onTap: handleState(bangumiIntroController.actionLikeVideo), + onTap: () => + handleState(bangumiIntroController.actionLikeVideo), onLongPress: bangumiIntroController.actionOneThree, selectStatus: bangumiIntroController.hasLike.value, loadingStatus: false, @@ -477,7 +477,8 @@ class _BangumiInfoState extends State key: _coinKey, icon: const Icon(FontAwesomeIcons.b), selectIcon: const Icon(FontAwesomeIcons.b), - onTap: handleState(bangumiIntroController.actionCoinVideo), + onTap: () => + handleState(bangumiIntroController.actionCoinVideo), selectStatus: bangumiIntroController.hasCoin.value, loadingStatus: false, semanticsLabel: '投币', @@ -540,7 +541,7 @@ class _BangumiInfoState extends State Obx( () => ActionRowItem( icon: const Icon(FontAwesomeIcons.thumbsUp), - onTap: handleState(videoIntroController.actionLikeVideo), + onTap: () => handleState(videoIntroController.actionLikeVideo), selectStatus: videoIntroController.hasLike.value, loadingStatus: widget.loadingStatus, text: !widget.loadingStatus @@ -552,7 +553,7 @@ class _BangumiInfoState extends State Obx( () => ActionRowItem( icon: const Icon(FontAwesomeIcons.b), - onTap: handleState(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 c39776e03..3dfc9b043 100644 --- a/lib/pages/dynamics/widgets/action_panel.dart +++ b/lib/pages/dynamics/widgets/action_panel.dart @@ -2,6 +2,7 @@ import 'package:PiliPalaX/common/widgets/network_img_layer.dart'; import 'package:PiliPalaX/http/msg.dart'; +import 'package:PiliPalaX/utils/extension.dart'; import 'package:PiliPalaX/utils/storage.dart'; import 'package:flutter/material.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; @@ -27,14 +28,12 @@ class _ActionPanelState extends State { final DynamicsController _dynamicsController = Get.put(DynamicsController()); // late ModuleStatModel stat; bool isProcessing = false; - void Function()? handleState(Future Function() action) { - return isProcessing - ? null - : () async { - setState(() => isProcessing = true); - await action(); - setState(() => isProcessing = false); - }; + void handleState(Future Function() action) async { + if (isProcessing.not) { + isProcessing = true; + await action(); + isProcessing = false; + } } // @override @@ -136,7 +135,7 @@ class _ActionPanelState extends State { Expanded( flex: 1, child: TextButton.icon( - onPressed: handleState(onLikeDynamic), + onPressed: () => handleState(onLikeDynamic), icon: Icon( widget.item!.modules.moduleStat.like!.status! ? FontAwesomeIcons.solidThumbsUp diff --git a/lib/pages/video/detail/introduction/view.dart b/lib/pages/video/detail/introduction/view.dart index 22381b609..c1fca201a 100644 --- a/lib/pages/video/detail/introduction/view.dart +++ b/lib/pages/video/detail/introduction/view.dart @@ -152,14 +152,12 @@ class _VideoInfoState extends State with TickerProviderStateMixin { late final _horizontalMemberPage = GStorage.horizontalMemberPage; - void Function()? handleState(Future Function() action) { - return isProcessing - ? null - : () async { - setState(() => isProcessing = true); - await action(); - setState(() => isProcessing = false); - }; + void handleState(Future Function() action) async { + if (isProcessing.not) { + isProcessing = true; + await action(); + isProcessing = false; + } } @override @@ -738,8 +736,9 @@ class _VideoInfoState extends State with TickerProviderStateMixin { () => ActionItem( icon: const Icon(FontAwesomeIcons.thumbsUp), selectIcon: const Icon(FontAwesomeIcons.solidThumbsUp), - onTap: handleState(videoIntroController.actionLikeVideo), - onLongPress: handleState(videoIntroController.actionOneThree), + onTap: () => handleState(videoIntroController.actionLikeVideo), + onLongPress: () => + handleState(videoIntroController.actionOneThree), selectStatus: videoIntroController.hasLike.value, loadingStatus: widget.loadingStatus, semanticsLabel: '点赞', @@ -765,7 +764,8 @@ class _VideoInfoState extends State with TickerProviderStateMixin { () => ActionItem( icon: const Icon(FontAwesomeIcons.thumbsDown), selectIcon: const Icon(FontAwesomeIcons.solidThumbsDown), - onTap: handleState(videoIntroController.actionDislikeVideo), + onTap: () => + handleState(videoIntroController.actionDislikeVideo), selectStatus: videoIntroController.hasDislike.value, loadingStatus: widget.loadingStatus, semanticsLabel: '点踩', @@ -782,7 +782,7 @@ class _VideoInfoState extends State with TickerProviderStateMixin { key: _coinKey, icon: const Icon(FontAwesomeIcons.b), selectIcon: const Icon(FontAwesomeIcons.b), - onTap: handleState(videoIntroController.actionCoinVideo), + onTap: () => handleState(videoIntroController.actionCoinVideo), selectStatus: videoIntroController.hasCoin.value, loadingStatus: widget.loadingStatus, semanticsLabel: '投币', @@ -838,7 +838,7 @@ class _VideoInfoState extends State with TickerProviderStateMixin { Obx( () => ActionRowItem( icon: const Icon(FontAwesomeIcons.thumbsUp), - onTap: handleState(videoIntroController.actionLikeVideo), + onTap: () => handleState(videoIntroController.actionLikeVideo), selectStatus: videoIntroController.hasLike.value, loadingStatus: widget.loadingStatus, text: !widget.loadingStatus @@ -850,7 +850,7 @@ class _VideoInfoState extends State with TickerProviderStateMixin { Obx( () => ActionRowItem( icon: const Icon(FontAwesomeIcons.b), - onTap: handleState(videoIntroController.actionCoinVideo), + onTap: () => handleState(videoIntroController.actionCoinVideo), selectStatus: videoIntroController.hasCoin.value, loadingStatus: widget.loadingStatus, text: !widget.loadingStatus diff --git a/lib/pages/video/detail/reply/widgets/zan.dart b/lib/pages/video/detail/reply/widgets/zan.dart index 7d25693e9..28b819e94 100644 --- a/lib/pages/video/detail/reply/widgets/zan.dart +++ b/lib/pages/video/detail/reply/widgets/zan.dart @@ -1,3 +1,4 @@ +import 'package:PiliPalaX/utils/extension.dart'; import 'package:flutter/material.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; @@ -81,14 +82,12 @@ class _ZanButtonState extends State { } bool isProcessing = false; - void Function()? handleState(Future Function() action) { - return isProcessing - ? null - : () async { - setState(() => isProcessing = true); - await action(); - setState(() => isProcessing = false); - }; + void handleState(Future Function() action) async { + if (isProcessing.not) { + isProcessing = true; + await action(); + isProcessing = false; + } } @override @@ -102,7 +101,7 @@ class _ZanButtonState extends State { SizedBox( height: 32, child: TextButton( - onPressed: handleState(onHateReply), + onPressed: () => handleState(onHateReply), child: Icon( widget.replyItem!.action == 2 ? FontAwesomeIcons.solidThumbsDown @@ -116,7 +115,7 @@ class _ZanButtonState extends State { SizedBox( height: 32, child: TextButton( - onPressed: handleState(onLikeReply), + onPressed: () => handleState(onLikeReply), child: Row( children: [ Icon( diff --git a/lib/pages/video/detail/reply/widgets/zan_grpc.dart b/lib/pages/video/detail/reply/widgets/zan_grpc.dart index 95d6b5162..2a11b13c2 100644 --- a/lib/pages/video/detail/reply/widgets/zan_grpc.dart +++ b/lib/pages/video/detail/reply/widgets/zan_grpc.dart @@ -1,4 +1,5 @@ import 'package:PiliPalaX/grpc/app/main/community/reply/v1/reply.pb.dart'; +import 'package:PiliPalaX/utils/extension.dart'; import 'package:flutter/material.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; @@ -91,14 +92,12 @@ class _ZanButtonGrpcState extends State { } bool isProcessing = false; - void Function()? handleState(Future Function() action) { - return isProcessing - ? null - : () async { - setState(() => isProcessing = true); - await action(); - setState(() => isProcessing = false); - }; + void handleState(Future Function() action) async { + if (isProcessing.not) { + isProcessing = true; + await action(); + isProcessing = false; + } } get _style => TextButton.styleFrom( @@ -119,7 +118,7 @@ class _ZanButtonGrpcState extends State { height: 32, child: TextButton( style: _style, - onPressed: handleState(onHateReply), + onPressed: () => handleState(onHateReply), child: Icon( widget.replyItem.replyControl.action.toInt() == 2 ? FontAwesomeIcons.solidThumbsDown @@ -138,7 +137,7 @@ class _ZanButtonGrpcState extends State { height: 32, child: TextButton( style: _style, - onPressed: handleState(onLikeReply), + onPressed: () => handleState(onLikeReply), child: Row( children: [ Icon(