Skip to content

Instantly share code, notes, and snippets.

@BarryDaBee
Created January 4, 2021 01:27
Show Gist options
  • Save BarryDaBee/ebf23d37cf3c903b2a5aab3f9a605bfc to your computer and use it in GitHub Desktop.
Save BarryDaBee/ebf23d37cf3c903b2a5aab3f9a605bfc to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
import 'dart:math';
void main(){
runApp(MyApp());
}
class MyApp extends StatelessWidget{
@override
Widget build(BuildContext context){
return MaterialApp(
home: RotatingLoadingAnimation(),
);
}
}
class RotatingLoadingAnimation extends StatefulWidget{
@override
_RotatingLoadingAnimationState createState() => _RotatingLoadingAnimationState();
}
class _RotatingLoadingAnimationState extends State<RotatingLoadingAnimation> with SingleTickerProviderStateMixin{
AnimationController _controller;
bool _completed = false;
@override
void initState(){
_controller = AnimationController(vsync: this, duration: Duration(seconds: 3),);
_controller.forward().whenComplete(()=>setState((){_completed = true;}),);
_controller.addListener((){
setState((){});
});
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Center(
child: !_completed?Stack(
children: [
Transform.rotate(
angle: 20 * _controller.value,
child: Container(
height: 50,
width: 50,
child: CustomPaint(
painter: RollingThingy(color: Colors.green),
),
),
),
Positioned(
top: 5,
left: 5,
bottom: 5,
right: 5,
child: Padding(
padding: const EdgeInsets.all(3.0),
child: Transform.rotate(
angle: 20 - (20 * _controller.value),
child: Container(
height: 40,
width: 40,
child: CustomPaint(
painter: RollingThingy(color: Colors.greenAccent),
),
),
),
),
),
],
): Container(
height: 50,
width: 50,
child: CustomPaint(
painter: CustomCheckIcon(),
),
),
),
SizedBox(height: 20),
Text(
!_completed?'${(_controller.value * 100).round()}%':'Completed',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.w700,
),
),
],
),
);
}
}
class RollingThingy extends CustomPainter{
final Color color;
RollingThingy({this.color});
@override
void paint(Canvas canvas, Size size) {
Paint paint = Paint()
..color = color??Colors.orange
..strokeWidth = 6.3
..style = PaintingStyle.stroke
..strokeCap = StrokeCap.round;
canvas.drawArc(Offset(0, 0) & size, 0, 2, false, paint);
canvas.drawArc(Offset(0, 0) & size, 3, 2, false, paint);
}
@override
bool shouldRepaint(covariant CustomPainter oldDelegate) {
return false;
}
}
class CustomCheckIcon extends CustomPainter{
@override
void paint(Canvas canvas, Size size) {
Paint paint = Paint()
..color = Colors.green
..strokeWidth = 6.3
..style = PaintingStyle.stroke
..strokeCap = StrokeCap.round;
double centerX = size.width/2;
double centerY = size.height/2;
Path path = Path()
..moveTo(centerX-15, centerY)
..lineTo(centerX -8, centerY + 8)
..lineTo(centerX + 15, centerY -8);
double radius = min(centerX, centerY);
canvas.drawCircle(Offset(centerX, centerY), radius, paint);
canvas.drawPath(path, paint);
}
@override
bool shouldRepaint(covariant CustomPainter oldDelegate) {
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment