| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- 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<StatefulWidget> createState() {
- return _RotateImageState();
- }
- }
- class _RotateImageState extends State<RotateImage>
- 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,
- );
- }
- }
|