Created
January 29, 2020 15:22
-
-
Save ericorruption/5b8f12995150c56b87c15eafb6e8c8c2 to your computer and use it in GitHub Desktop.
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
import 'dart:math' as math; | |
import 'package:flutter/material.dart'; | |
class Spinner extends StatefulWidget { | |
final Widget child; | |
final bool reverse; | |
const Spinner({Key key, @required this.child, this.reverse = false}) | |
: super(key: key); | |
@override | |
_SpinnerState createState() => _SpinnerState(); | |
} | |
class _SpinnerState extends State<Spinner> with SingleTickerProviderStateMixin { | |
AnimationController _controller; | |
@override | |
void initState() { | |
super.initState(); | |
_controller = AnimationController( | |
duration: const Duration(seconds: 1), | |
vsync: this, | |
)..repeat(); | |
} | |
@override | |
void dispose() { | |
_controller.dispose(); | |
super.dispose(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return AnimatedBuilder( | |
animation: _controller, | |
child: widget.child, | |
builder: (BuildContext context, Widget child) { | |
return Transform.rotate( | |
angle: _controller.value * (widget.reverse ? -2 : 2) * math.pi, | |
child: child, | |
); | |
}, | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment