Skip to content

Instantly share code, notes, and snippets.

@ericorruption
Created January 29, 2020 15:22
Show Gist options
  • Save ericorruption/5b8f12995150c56b87c15eafb6e8c8c2 to your computer and use it in GitHub Desktop.
Save ericorruption/5b8f12995150c56b87c15eafb6e8c8c2 to your computer and use it in GitHub Desktop.
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