2023-05-12 22:23:40 +00:00
|
|
|
import 'package:flutter/widgets.dart';
|
|
|
|
|
|
|
|
class RotateIconController {
|
2023-05-15 15:55:49 +00:00
|
|
|
// VoidCallback? forward;
|
|
|
|
VoidCallback? repeat;
|
2023-05-12 22:23:40 +00:00
|
|
|
VoidCallback? reset;
|
|
|
|
}
|
|
|
|
|
|
|
|
class RotateIcon extends StatefulWidget {
|
|
|
|
const RotateIcon({
|
|
|
|
Key? key,
|
|
|
|
required this.icon,
|
|
|
|
required this.curve,
|
|
|
|
this.controller,
|
|
|
|
this.animationDurationMultiplier = 1.0,
|
|
|
|
this.rotationPercent = 0.5,
|
|
|
|
}) : super(key: key);
|
|
|
|
|
|
|
|
final Widget icon;
|
|
|
|
final Curve curve;
|
|
|
|
final RotateIconController? controller;
|
|
|
|
final double animationDurationMultiplier;
|
|
|
|
final double rotationPercent;
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<RotateIcon> createState() => _RotateIconState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _RotateIconState extends State<RotateIcon>
|
|
|
|
with SingleTickerProviderStateMixin {
|
|
|
|
late final AnimationController animationController;
|
|
|
|
late final Animation<double> animation;
|
|
|
|
late final Duration duration;
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
duration = Duration(
|
|
|
|
milliseconds: (500 * widget.animationDurationMultiplier).toInt(),
|
|
|
|
);
|
|
|
|
animationController = AnimationController(
|
|
|
|
vsync: this,
|
|
|
|
duration: duration,
|
|
|
|
);
|
|
|
|
animation = Tween<double>(
|
|
|
|
begin: 0.0,
|
|
|
|
end: widget.rotationPercent,
|
|
|
|
).animate(
|
|
|
|
CurvedAnimation(
|
|
|
|
curve: widget.curve,
|
|
|
|
parent: animationController,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2023-05-15 15:55:49 +00:00
|
|
|
// widget.controller?.forward = animationController.forward;
|
|
|
|
widget.controller?.repeat = animationController.repeat;
|
2023-05-12 22:23:40 +00:00
|
|
|
widget.controller?.reset = animationController.reset;
|
|
|
|
|
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void dispose() {
|
|
|
|
animationController.dispose();
|
2023-05-15 15:55:49 +00:00
|
|
|
// widget.controller?.forward = null;
|
|
|
|
widget.controller?.repeat = null;
|
2023-05-12 22:23:40 +00:00
|
|
|
super.dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return RotationTransition(
|
|
|
|
turns: animation,
|
|
|
|
child: widget.icon,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|