rustdesk/flutter/lib/common/widgets/animated_rotation_widget.dart
21pages 24e6b54650 don't use Offstage as widget of animated loading, reuse refresh as
loading

Signed-off-by: 21pages <pages21@163.com>
2023-08-18 12:58:37 +08:00

54 lines
1.3 KiB
Dart

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));
}
}