import 'package:flutter/cupertino.dart'; /// 旋转图片组件 class RotateImage extends StatefulWidget { /// 图片组件 final Image image; /// 动画时长 final Duration duration; const RotateImage({ super.key, required this.image, this.duration = const Duration(milliseconds: 1000), }); @override State createState() { return _RotateImageState(); } } class _RotateImageState extends State with SingleTickerProviderStateMixin { /// 动画控制器 late AnimationController _animationController; @override void initState() { super.initState(); _animationController = AnimationController(duration: widget.duration, vsync: this) // 无限循环 ..repeat(); } @override void dispose() { // 释放资源 _animationController.dispose(); super.dispose(); } @override Widget build(BuildContext context) { // 动画组件 return RotationTransition( turns: _animationController, child: widget.image, ); } }