Last active
August 24, 2021 15:36
-
-
Save GitHubStuff/0207ac584aa6acd8b4f3fa11615801be to your computer and use it in GitHub Desktop.
Flutter rotating widget
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Continuous rotattion of a widget | |
/// [widget] - Widget to rotate {required} | |
/// [duration] - Duration of the rotation (default [Duration(seconds:15)]) | |
import 'package:flutter/material.dart'; | |
class RotatingAnimationWidget extends StatefulWidget { | |
final Widget rotatingWidget; | |
final Duration duration; | |
const RotatingAnimationWidget(this.rotatingWidget, {this.duration}) : assert(rotatingWidget != null); | |
_RotatingAnimationWidget createState() => _RotatingAnimationWidget(); | |
} | |
class _RotatingAnimationWidget extends State<RotatingAnimationWidget> with SingleTickerProviderStateMixin { | |
AnimationController _animationController; | |
Duration _duration; | |
@override | |
void initState() { | |
super.initState(); | |
_duration = widget.duration ?? Duration(seconds: 15); | |
_animationController = AnimationController(vsync: this, duration: _duration)..repeat(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return RotationTransition( | |
alignment: Alignment.center, | |
turns: _animationController, | |
child: widget.rotatingWidget, | |
); | |
} | |
@override | |
void dispose() { | |
_animationController.dispose(); | |
super.dispose(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Helpful
Thanxs