50 lines
1.0 KiB
Dart
50 lines
1.0 KiB
Dart
|
|
import 'package:flutter/material.dart';
|
||
|
|
|
||
|
|
class RotatingImage extends StatefulWidget {
|
||
|
|
final String imagePath;
|
||
|
|
final double size;
|
||
|
|
final Duration duration;
|
||
|
|
|
||
|
|
const RotatingImage({
|
||
|
|
Key? key,
|
||
|
|
required this.imagePath,
|
||
|
|
this.size = 20,
|
||
|
|
this.duration = const Duration(seconds: 3)
|
||
|
|
}) : super(key: key);
|
||
|
|
|
||
|
|
@override
|
||
|
|
State<RotatingImage> createState() => _RotatingImageState();
|
||
|
|
}
|
||
|
|
|
||
|
|
class _RotatingImageState extends State<RotatingImage>
|
||
|
|
with SingleTickerProviderStateMixin {
|
||
|
|
late AnimationController _controller;
|
||
|
|
|
||
|
|
@override
|
||
|
|
void initState() {
|
||
|
|
super.initState();
|
||
|
|
_controller = AnimationController(
|
||
|
|
duration: widget.duration,
|
||
|
|
vsync: this,
|
||
|
|
)..repeat();
|
||
|
|
}
|
||
|
|
|
||
|
|
@override
|
||
|
|
void dispose() {
|
||
|
|
_controller.dispose();
|
||
|
|
super.dispose();
|
||
|
|
}
|
||
|
|
|
||
|
|
@override
|
||
|
|
Widget build(BuildContext context) {
|
||
|
|
return RotationTransition(
|
||
|
|
turns: _controller,
|
||
|
|
child: Image.asset(
|
||
|
|
widget.imagePath,
|
||
|
|
width: widget.size,
|
||
|
|
height: widget.size
|
||
|
|
),
|
||
|
|
);
|
||
|
|
}
|
||
|
|
}
|