opt action item

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
bggRGjQaUbCoE
2025-08-09 19:19:08 +08:00
parent 85c72731f6
commit 30aa29598b

View File

@@ -75,7 +75,7 @@ mixin TripleAnimMixin<T extends StatefulWidget>
} }
} }
class ActionItem extends StatefulWidget { class ActionItem extends StatelessWidget {
const ActionItem({ const ActionItem({
super.key, super.key,
required this.icon, required this.icon,
@@ -90,7 +90,7 @@ class ActionItem extends StatefulWidget {
this.animation, this.animation,
this.onStartTriple, this.onStartTriple,
this.onCancelTriple, this.onCancelTriple,
}); }) : isThumbsUp = onStartTriple != null;
final Icon icon; final Icon icon;
final Icon? selectIcon; final Icon? selectIcon;
@@ -104,38 +104,31 @@ class ActionItem extends StatefulWidget {
final Animation<double>? animation; final Animation<double>? animation;
final VoidCallback? onStartTriple; final VoidCallback? onStartTriple;
final ValueChanged<bool>? onCancelTriple; final ValueChanged<bool>? onCancelTriple;
final bool isThumbsUp;
@override
State<ActionItem> createState() => ActionItemState();
}
class ActionItemState extends State<ActionItem>
with SingleTickerProviderStateMixin {
late final _isThumbsUp = widget.onStartTriple != null;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final theme = Theme.of(context); final theme = Theme.of(context);
Widget? text; Widget? textWidget;
if (widget.expand) { if (expand) {
final hasText = widget.text != null; final hasText = text != null;
text = Text( textWidget = Text(
hasText ? widget.text! : '-', hasText ? text! : '-',
key: hasText ? ValueKey(widget.text!) : null, key: hasText ? ValueKey(text!) : null,
style: TextStyle( style: TextStyle(
color: widget.selectStatus color: selectStatus
? theme.colorScheme.primary ? theme.colorScheme.primary
: theme.colorScheme.outline, : theme.colorScheme.outline,
fontSize: theme.textTheme.labelSmall!.fontSize, fontSize: theme.textTheme.labelSmall!.fontSize,
), ),
); );
if (hasText) { if (hasText) {
text = AnimatedSwitcher( textWidget = AnimatedSwitcher(
duration: const Duration(milliseconds: 300), duration: const Duration(milliseconds: 300),
transitionBuilder: (Widget child, Animation<double> animation) { transitionBuilder: (Widget child, Animation<double> animation) {
return ScaleTransition(scale: animation, child: child); return ScaleTransition(scale: animation, child: child);
}, },
child: text, child: textWidget,
); );
} }
} }
@@ -143,18 +136,16 @@ class ActionItemState extends State<ActionItem>
type: MaterialType.transparency, type: MaterialType.transparency,
child: InkWell( child: InkWell(
borderRadius: const BorderRadius.all(Radius.circular(6)), borderRadius: const BorderRadius.all(Radius.circular(6)),
onTap: _isThumbsUp onTap: isThumbsUp
? null ? null
: () { : () {
feedBack(); feedBack();
widget.onTap?.call(); onTap?.call();
}, },
onLongPress: _isThumbsUp ? null : widget.onLongPress, onLongPress: isThumbsUp ? null : onLongPress,
onTapDown: _isThumbsUp ? (details) => widget.onStartTriple!() : null, onTapDown: isThumbsUp ? (details) => onStartTriple!() : null,
onTapUp: _isThumbsUp onTapUp: isThumbsUp ? (details) => onCancelTriple!(false) : null,
? (details) => widget.onCancelTriple!(false) onTapCancel: isThumbsUp ? () => onCancelTriple!(true) : null,
: null,
onTapCancel: _isThumbsUp ? () => widget.onCancelTriple!(true) : null,
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
@@ -162,36 +153,34 @@ class ActionItemState extends State<ActionItem>
clipBehavior: Clip.none, clipBehavior: Clip.none,
alignment: Alignment.center, alignment: Alignment.center,
children: [ children: [
if (widget.animation != null) if (animation != null)
AnimatedBuilder( AnimatedBuilder(
animation: widget.animation!, animation: animation!,
builder: (context, child) => CustomPaint( builder: (context, child) => CustomPaint(
size: const Size(28, 28), size: const Size(28, 28),
painter: _ArcPainter( painter: _ArcPainter(
color: theme.colorScheme.primary, color: theme.colorScheme.primary,
sweepAngle: widget.animation!.value, sweepAngle: animation!.value,
), ),
), ),
) )
else else
const SizedBox(width: 28, height: 28), const SizedBox(width: 28, height: 28),
Icon( Icon(
widget.selectStatus selectStatus ? selectIcon!.icon! : icon.icon,
? widget.selectIcon!.icon!
: widget.icon.icon,
size: 18, size: 18,
color: widget.selectStatus color: selectStatus
? theme.colorScheme.primary ? theme.colorScheme.primary
: widget.icon.color ?? theme.colorScheme.outline, : icon.color ?? theme.colorScheme.outline,
), ),
], ],
), ),
?text, ?textWidget,
], ],
), ),
), ),
); );
return widget.expand ? Expanded(child: child) : child; return expand ? Expanded(child: child) : child;
} }
} }