Created
July 11, 2019 16:45
-
-
Save kascote/0dac03ceb84286bb56c6c37994992a37 to your computer and use it in GitHub Desktop.
flutter icon spinner
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
// | |
// https://stackoverflow.com/questions/55431496/font-awesome-spinners-icons-not-spinning-in-flutter | |
// | |
// Usage: | |
// Spinner( | |
// icon: FontAwesomeIcons.spinner, | |
// ) | |
// | |
class Spinner extends StatefulWidget { | |
final IconData icon; | |
final Duration duration; | |
const Spinner({ | |
Key key, | |
@required this.icon, | |
this.duration = const Duration(milliseconds: 1800), | |
}) : super(key: key); | |
@override | |
_SpinnerState createState() => _SpinnerState(); | |
} | |
class _SpinnerState extends State<Spinner> with SingleTickerProviderStateMixin { | |
AnimationController _controller; | |
Widget _child; | |
@override | |
void initState() { | |
_controller = AnimationController( | |
vsync: this, | |
duration: Duration(milliseconds: 2000), | |
)..repeat(); | |
_child = Icon(widget.icon); | |
super.initState(); | |
} | |
@override | |
void dispose() { | |
_controller.dispose(); | |
super.dispose(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return RotationTransition( | |
turns: _controller, | |
child: _child, | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment