Skip to content

Instantly share code, notes, and snippets.

@GitHubStuff
Last active August 24, 2021 15:36
Show Gist options
  • Save GitHubStuff/0207ac584aa6acd8b4f3fa11615801be to your computer and use it in GitHub Desktop.
Save GitHubStuff/0207ac584aa6acd8b4f3fa11615801be to your computer and use it in GitHub Desktop.
Flutter rotating widget
/// 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();
}
}
@GitHubStuff
Copy link
Author

Continuous rotating widget

@AyoubBenBrahim
Copy link

Helpful
Thanxs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment