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

@@ -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(