Created
March 23, 2021 11:10
-
-
Save alexmercerind/525cc094fce7563cd05e8992240a9793 to your computer and use it in GitHub Desktop.
a thing
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'; | |
import 'package:flutter/material.dart'; | |
class WindowsLoader extends StatefulWidget { | |
final double size; | |
final Color color; | |
WindowsLoader({@required this.size,@required this.color}); | |
_WindowsLoaderState createState() => _WindowsLoaderState(); | |
} | |
class _WindowsLoaderState extends State<WindowsLoader> with TickerProviderStateMixin { | |
AnimationController _controller; | |
Animation<double> _animation; | |
AnimationController _controllerAcc; | |
Animation<double> _animationAcc; | |
AnimationController _controller1; | |
Animation<double> _animation1; | |
AnimationController _controllerAcc1; | |
Animation<double> _animationAcc1; | |
AnimationController _controller2; | |
Animation<double> _animation2; | |
AnimationController _controllerAcc2; | |
Animation<double> _animationAcc2; | |
AnimationController _controller3; | |
Animation<double> _animation3; | |
AnimationController _controllerAcc3; | |
Animation<double> _animationAcc3; | |
AnimationController _controller4; | |
Animation<double> _animation4; | |
AnimationController _controllerAcc4; | |
Animation<double> _animationAcc4; | |
void startAnimation() { | |
new Future.delayed(const Duration(milliseconds: 0), () {_controller.forward(); _controllerAcc.forward();}); | |
new Future.delayed(const Duration(milliseconds: 250), () {_controller1.forward(); _controllerAcc1.forward();}); | |
new Future.delayed(const Duration(milliseconds: 500), () {_controller2.forward(); _controllerAcc2.forward();}); | |
new Future.delayed(const Duration(milliseconds: 750), () {_controller3.forward(); _controllerAcc3.forward();}); | |
new Future.delayed(const Duration(milliseconds: 1000),() {_controller4.forward(); _controllerAcc4.forward();}); | |
} | |
@override | |
void initState() { | |
super.initState(); | |
_controllerAcc = AnimationController( | |
vsync: this, | |
duration: Duration(seconds: 1) | |
); | |
_animationAcc = Tween<double>(begin: 0, end: pi).animate(new CurvedAnimation( | |
curve: Curves.easeInOutCubic, | |
parent: _controllerAcc) | |
); | |
_controller = AnimationController( | |
vsync: this, | |
duration: Duration(seconds: 2) | |
); | |
_animation = Tween<double>(begin: 0, end: pi).animate(new CurvedAnimation( | |
curve: Curves.linear, | |
parent: _controller))..addListener(() { | |
setState(() { | |
if (_controller.isCompleted) { | |
_controller..reset()..forward(); | |
_controllerAcc..reset()..forward(); | |
} | |
}); | |
}); | |
_controllerAcc1 = AnimationController( | |
vsync: this, | |
duration: Duration(seconds: 1) | |
); | |
_animationAcc1 = Tween<double>(begin: 0, end: pi).animate(new CurvedAnimation( | |
curve: Curves.easeInOutCubic, | |
parent: _controllerAcc1) | |
); | |
_controller1 = AnimationController( | |
vsync: this, | |
duration: Duration(seconds: 2) | |
); | |
_animation1 = Tween<double>(begin: 0, end: pi).animate(new CurvedAnimation( | |
curve: Curves.linear, | |
parent: _controller1))..addListener(() { | |
setState(() { | |
setState(() { | |
if (_controller1.isCompleted) { | |
_controller1..reset()..forward(); | |
_controllerAcc1..reset()..forward(); | |
} | |
}); | |
}); | |
}); | |
_controllerAcc2 = AnimationController( | |
vsync: this, | |
duration: Duration(seconds: 1) | |
); | |
_animationAcc2 = Tween<double>(begin: 0, end: pi).animate(new CurvedAnimation( | |
curve: Curves.easeInOutCubic, | |
parent: _controllerAcc2) | |
); | |
_controller2 = AnimationController( | |
vsync: this, | |
duration: Duration(seconds: 2) | |
); | |
_animation2 = Tween<double>(begin: 0, end: pi).animate(new CurvedAnimation( | |
curve: Curves.linear, | |
parent: _controller2))..addListener(() { | |
setState(() { | |
setState(() { | |
if (_controller2.isCompleted) { | |
_controller2..reset()..forward(); | |
_controllerAcc2..reset()..forward(); | |
} | |
}); | |
}); | |
}); | |
_controllerAcc3 = AnimationController( | |
vsync: this, | |
duration: Duration(seconds: 1) | |
); | |
_animationAcc3 = Tween<double>(begin: 0, end: pi).animate(new CurvedAnimation( | |
curve: Curves.easeInOutCubic, | |
parent: _controllerAcc3) | |
); | |
_controller3 = AnimationController( | |
vsync: this, | |
duration: Duration(seconds: 2) | |
); | |
_animation3 = Tween<double>(begin: 0, end: pi).animate(new CurvedAnimation( | |
curve: Curves.linear, | |
parent: _controller3))..addListener(() { | |
setState(() { | |
setState(() { | |
if (_controller3.isCompleted) { | |
_controller3..reset()..forward(); | |
_controllerAcc3..reset()..forward(); | |
} | |
}); | |
}); | |
}); | |
_controllerAcc4 = AnimationController( | |
vsync: this, | |
duration: Duration(seconds: 1) | |
); | |
_animationAcc4 = Tween<double>(begin: 0, end: pi).animate(new CurvedAnimation( | |
curve: Curves.easeInOutCubic, | |
parent: _controllerAcc4) | |
); | |
_controller4 = AnimationController( | |
vsync: this, | |
duration: Duration(seconds: 2) | |
); | |
_animation4 = Tween<double>(begin: 0, end: pi).animate(new CurvedAnimation( | |
curve: Curves.linear, | |
parent: _controller4))..addListener(() { | |
setState(() { | |
setState(() { | |
if (_controller4.isCompleted) { | |
_controller4..reset()..forward(); | |
_controllerAcc4..reset()..forward(); | |
} | |
}); | |
}); | |
}); | |
new Future.delayed(Duration(milliseconds: 200), this.startAnimation); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Stack( | |
alignment: Alignment.center, | |
children: [ | |
Transform.rotate( | |
angle: _animation.value + _animationAcc.value + pi / 4, | |
alignment: Alignment.center, | |
child: Container( | |
height: widget.size, | |
width: widget.size, | |
alignment: Alignment.topLeft, | |
child: Container( | |
height: widget.size / 8, | |
width: widget.size / 8, | |
decoration: BoxDecoration(color: widget.color, shape: BoxShape.circle), | |
), | |
), | |
), | |
Transform.rotate( | |
angle: _animation1.value + _animationAcc1.value + pi / 4, | |
alignment: Alignment.center, | |
child: Container( | |
height: widget.size, | |
width: widget.size, | |
alignment: Alignment.topLeft, | |
child: Container( | |
height: widget.size / 8, | |
width: widget.size / 8, | |
decoration: BoxDecoration(color: widget.color, shape: BoxShape.circle), | |
), | |
), | |
), | |
Transform.rotate( | |
angle: _animation2.value + _animationAcc2.value + pi / 4, | |
alignment: Alignment.center, | |
child: Container( | |
height: widget.size, | |
width: widget.size, | |
alignment: Alignment.topLeft, | |
child: Container( | |
height: widget.size / 8, | |
width: widget.size / 8, | |
decoration: BoxDecoration(color: widget.color, shape: BoxShape.circle), | |
), | |
), | |
), | |
Transform.rotate( | |
angle: _animation3.value + _animationAcc3.value + pi / 4, | |
alignment: Alignment.center, | |
child: Container( | |
height: widget.size, | |
width: widget.size, | |
alignment: Alignment.topLeft, | |
child: Container( | |
height: widget.size / 8, | |
width: widget.size / 8, | |
decoration: BoxDecoration(color: widget.color, shape: BoxShape.circle), | |
), | |
), | |
), | |
Transform.rotate( | |
angle: _animation4.value + _animationAcc4.value + pi / 4, | |
alignment: Alignment.center, | |
child: Container( | |
height: widget.size, | |
width: widget.size, | |
alignment: Alignment.topLeft, | |
child: Container( | |
height: widget.size / 8, | |
width: widget.size / 8, | |
decoration: BoxDecoration(color: widget.color, shape: BoxShape.circle), | |
), | |
), | |
), | |
] | |
); | |
} | |
} | |
void main() { | |
runApp( | |
MaterialApp( | |
home: Scaffold( | |
body: Center( | |
child: WindowsLoader(size: 56.0, color: Colors.deepPurpleAccent), | |
), | |
), | |
), | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment