opt: handleState

weird

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
bggRGjQaUbCoE
2024-12-28 14:29:03 +08:00
parent 820c7aa324
commit 6260809e40
5 changed files with 53 additions and 55 deletions

View File

@@ -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<BangumiInfo>
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<ActionItemState>();
@@ -447,7 +446,8 @@ class _BangumiInfoState extends State<BangumiInfo>
() => 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<BangumiInfo>
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<BangumiInfo>
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<BangumiInfo>
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

View File

@@ -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<ActionPanel> {
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<ActionPanel> {
Expanded(
flex: 1,
child: TextButton.icon(
onPressed: handleState(onLikeDynamic),
onPressed: () => handleState(onLikeDynamic),
icon: Icon(
widget.item!.modules.moduleStat.like!.status!
? FontAwesomeIcons.solidThumbsUp

View File

@@ -152,14 +152,12 @@ class _VideoInfoState extends State<VideoInfo> 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<VideoInfo> 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<VideoInfo> 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<VideoInfo> 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<VideoInfo> 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<VideoInfo> 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

View File

@@ -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<ZanButton> {
}
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<ZanButton> {
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<ZanButton> {
SizedBox(
height: 32,
child: TextButton(
onPressed: handleState(onLikeReply),
onPressed: () => handleState(onLikeReply),
child: Row(
children: [
Icon(

View File

@@ -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<ZanButtonGrpc> {
}
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<ZanButtonGrpc> {
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<ZanButtonGrpc> {
height: 32,
child: TextButton(
style: _style,
onPressed: handleState(onLikeReply),
onPressed: () => handleState(onLikeReply),
child: Row(
children: [
Icon(