forked from rustdesk/rustdesk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanimated_rotation_widget.dart
53 lines (48 loc) · 1.28 KB
/
animated_rotation_widget.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import 'package:flutter/material.dart';
import 'package:get/get.dart';
class AnimatedRotationWidget extends StatefulWidget {
final VoidCallback onPressed;
final ValueChanged<bool>? onHover;
final Widget child;
final RxBool? spinning;
const AnimatedRotationWidget(
{super.key,
required this.onPressed,
required this.child,
this.spinning,
this.onHover});
@override
State<AnimatedRotationWidget> createState() => AnimatedRotationWidgetState();
}
class AnimatedRotationWidgetState extends State<AnimatedRotationWidget> {
double turns = 0.0;
@override
void initState() {
super.initState();
widget.spinning?.listen((v) {
if (v && mounted) {
setState(() {
turns += 1;
});
}
});
}
@override
Widget build(BuildContext context) {
return AnimatedRotation(
turns: turns,
duration: const Duration(milliseconds: 200),
onEnd: () {
if (widget.spinning?.value == true && mounted) {
setState(() => turns += 1.0);
}
},
child: InkWell(
onTap: () {
if (mounted) setState(() => turns += 1.0);
widget.onPressed();
},
onHover: widget.onHover,
child: widget.child));
}
}