Created
June 24, 2020 14:38
-
-
Save alexmercerind/809e256c21f380a94692cc5c5532e2ef to your computer and use it in GitHub Desktop.
alexmercerind
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 'package:flutter/material.dart'; | |
import 'dart:math'; | |
import 'dart:async'; | |
void main() { | |
runApp(new Application()); | |
} | |
class WindowsLoader extends StatefulWidget { | |
final double size; | |
final Color color; | |
WindowsLoader({this.size, this.color}); | |
_WindowsLoaderState createState() => _WindowsLoaderState(); | |
} | |
class _WindowsLoaderState extends State<WindowsLoader> | |
with TickerProviderStateMixin { | |
bool _startBool = true; | |
bool _startBool1 = true; | |
bool _startBool2 = true; | |
bool _startBool3 = true; | |
bool _startBool4 = true; | |
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; | |
@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 (0.03 >= num.parse(_controller.value.toStringAsFixed(2)) && num.parse(_controller.value.toStringAsFixed(2)) > 0 && _startBool) { | |
_controllerAcc.reset(); | |
_controllerAcc.forward(); | |
_startBool = false; | |
} | |
else if (1 >= num.parse(_controller.value.toStringAsFixed(2)) && num.parse(_controller.value.toStringAsFixed(2)) >= 0.98) { | |
_startBool = true; | |
} | |
}); | |
}); | |
_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(() { | |
if (0.03 >= num.parse(_controller1.value.toStringAsFixed(2)) && num.parse(_controller1.value.toStringAsFixed(2)) > 0 && _startBool1) { | |
_controllerAcc1.reset(); | |
_controllerAcc1.forward(); | |
_startBool1 = false; | |
} | |
else if (1 >= num.parse(_controller1.value.toStringAsFixed(2)) && num.parse(_controller1.value.toStringAsFixed(2)) >= 0.98) { | |
_startBool1 = true; | |
} | |
}); | |
}); | |
_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(() { | |
if (0.03 >= num.parse(_controller2.value.toStringAsFixed(2)) && num.parse(_controller2.value.toStringAsFixed(2)) > 0 && _startBool2) { | |
_controllerAcc2.reset(); | |
_controllerAcc2.forward(); | |
_startBool2 = false; | |
} | |
else if (1 >= num.parse(_controller2.value.toStringAsFixed(2)) && num.parse(_controller2.value.toStringAsFixed(2)) >= 0.98) { | |
_startBool2 = true; | |
} | |
}); | |
}); | |
_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(() { | |
if (0.03 >= num.parse(_controller3.value.toStringAsFixed(2)) && num.parse(_controller3.value.toStringAsFixed(2)) > 0 && _startBool3) { | |
_controllerAcc3.reset(); | |
_controllerAcc3.forward(); | |
_startBool3 = false; | |
} | |
else if (1 >= num.parse(_controller3.value.toStringAsFixed(2)) && num.parse(_controller3.value.toStringAsFixed(2)) >= 0.98) { | |
_startBool3 = true; | |
} | |
}); | |
}); | |
_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(() { | |
if (0.03 >= num.parse(_controller4.value.toStringAsFixed(2)) && num.parse(_controller4.value.toStringAsFixed(2)) > 0 && _startBool4) { | |
_controllerAcc4.reset(); | |
_controllerAcc4.forward(); | |
_startBool4 = false; | |
} | |
else if (1 >= num.parse(_controller4.value.toStringAsFixed(2)) && num.parse(_controller4.value.toStringAsFixed(2)) >= 0.98) { | |
_startBool4 = true; | |
} | |
}); | |
}); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Stack(alignment: Alignment.center, | |
children: [ | |
Column( | |
mainAxisSize: MainAxisSize.max, | |
mainAxisAlignment: MainAxisAlignment.spaceEvenly, | |
children: [ | |
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), | |
), | |
), | |
), | |
], | |
), | |
RaisedButton(child: Text("Change The State!"), onPressed: () { | |
if (_controller.isAnimating) { | |
_controller.stop(); | |
_controller1.stop(); | |
_controller2.stop(); | |
_controller3.stop(); | |
_controller4.stop(); | |
} | |
else { | |
_controller.repeat(); | |
new Future.delayed(const Duration(milliseconds: 250), _controller1.repeat); | |
new Future.delayed(const Duration(milliseconds: 500), _controller2.repeat); | |
new Future.delayed(const Duration(milliseconds: 750), _controller3.repeat); | |
new Future.delayed(const Duration(milliseconds: 1000), _controller4.repeat); | |
} | |
},) | |
],) | |
], | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment