2023-06-21 11:51:35 +08:00
|
|
|
import 'package:flutter/material.dart';
|
2023-08-18 12:52:50 +08:00
|
|
|
import 'package:get/get.dart';
|
2023-06-21 11:51:35 +08:00
|
|
|
|
|
|
|
class AnimatedRotationWidget extends StatefulWidget {
|
|
|
|
final VoidCallback onPressed;
|
|
|
|
final ValueChanged<bool>? onHover;
|
|
|
|
final Widget child;
|
2023-08-18 12:52:50 +08:00
|
|
|
final RxBool? spinning;
|
2023-06-21 11:51:35 +08:00
|
|
|
const AnimatedRotationWidget(
|
2023-08-18 12:52:50 +08:00
|
|
|
{super.key,
|
|
|
|
required this.onPressed,
|
|
|
|
required this.child,
|
|
|
|
this.spinning,
|
|
|
|
this.onHover});
|
2023-06-21 11:51:35 +08:00
|
|
|
|
|
|
|
@override
|
|
|
|
State<AnimatedRotationWidget> createState() => AnimatedRotationWidgetState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class AnimatedRotationWidgetState extends State<AnimatedRotationWidget> {
|
|
|
|
double turns = 0.0;
|
|
|
|
|
2023-08-18 12:52:50 +08:00
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
widget.spinning?.listen((v) {
|
|
|
|
if (v && mounted) {
|
|
|
|
setState(() {
|
|
|
|
turns += 1;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-06-21 11:51:35 +08:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return AnimatedRotation(
|
|
|
|
turns: turns,
|
|
|
|
duration: const Duration(milliseconds: 200),
|
2023-08-18 12:52:50 +08:00
|
|
|
onEnd: () {
|
|
|
|
if (widget.spinning?.value == true && mounted) {
|
|
|
|
setState(() => turns += 1.0);
|
|
|
|
}
|
|
|
|
},
|
2023-06-21 11:51:35 +08:00
|
|
|
child: InkWell(
|
|
|
|
onTap: () {
|
2023-08-18 12:52:50 +08:00
|
|
|
if (mounted) setState(() => turns += 1.0);
|
2023-06-21 11:51:35 +08:00
|
|
|
widget.onPressed();
|
|
|
|
},
|
|
|
|
onHover: widget.onHover,
|
|
|
|
child: widget.child));
|
|
|
|
}
|
|
|
|
}
|