|
| 1 | +import 'package:flutter/material.dart'; |
| 2 | +import 'dart:math'; |
| 3 | + |
| 4 | +class ColorLoader2 extends StatefulWidget { |
| 5 | + @override |
| 6 | + _ColorLoader2State createState() => _ColorLoader2State(); |
| 7 | +} |
| 8 | + |
| 9 | +class _ColorLoader2State extends State<ColorLoader2> with TickerProviderStateMixin { |
| 10 | + |
| 11 | + Animation<double> animation1; |
| 12 | + Animation<double> animation2; |
| 13 | + Animation<double> animation3; |
| 14 | + AnimationController controller1; |
| 15 | + AnimationController controller2; |
| 16 | + AnimationController controller3; |
| 17 | + |
| 18 | + @override |
| 19 | + void initState() { |
| 20 | + super.initState(); |
| 21 | + |
| 22 | + controller1 = AnimationController( |
| 23 | + duration: const Duration(milliseconds: 1200), vsync: this); |
| 24 | + |
| 25 | + controller2 = AnimationController( |
| 26 | + duration: const Duration(milliseconds: 900), vsync: this); |
| 27 | + |
| 28 | + controller3 = AnimationController( |
| 29 | + duration: const Duration(milliseconds: 2000), vsync: this); |
| 30 | + |
| 31 | + animation1 = Tween<double>(begin: 0.0, end: 1.0).animate(CurvedAnimation( |
| 32 | + parent: controller1, |
| 33 | + curve: Interval( |
| 34 | + 0.0, 1.0, curve: Curves.linear |
| 35 | + ) |
| 36 | + )); |
| 37 | + |
| 38 | + animation2 = Tween<double>(begin: -1.0, end: 0.0).animate(CurvedAnimation( |
| 39 | + parent: controller2, |
| 40 | + curve: Interval( |
| 41 | + 0.0, 1.0, curve: Curves.easeIn |
| 42 | + ) |
| 43 | + )); |
| 44 | + |
| 45 | + animation3 = Tween<double>(begin: 0.0, end: 1.0).animate(CurvedAnimation( |
| 46 | + parent: controller3, |
| 47 | + curve: Interval( |
| 48 | + 0.0, 1.0, curve: Curves.decelerate |
| 49 | + ) |
| 50 | + )); |
| 51 | + |
| 52 | + controller1.repeat(); |
| 53 | + controller2.repeat(); |
| 54 | + controller3.repeat(); |
| 55 | + } |
| 56 | + |
| 57 | + |
| 58 | + @override |
| 59 | + Widget build(BuildContext context) { |
| 60 | + return Container( |
| 61 | + child: Stack( |
| 62 | + children: <Widget>[ |
| 63 | + new RotationTransition( |
| 64 | + turns: animation1, |
| 65 | + child: CustomPaint( |
| 66 | + painter: Arc1Painter(), |
| 67 | + child: Container( |
| 68 | + width: 50.0, |
| 69 | + height: 50.0, |
| 70 | + ), |
| 71 | + ), |
| 72 | + ), new RotationTransition( |
| 73 | + turns: animation2, |
| 74 | + child: CustomPaint( |
| 75 | + painter: Arc2Painter(), |
| 76 | + child: Container( |
| 77 | + width: 50.0, |
| 78 | + height: 50.0, |
| 79 | + ), |
| 80 | + ), |
| 81 | + ), new RotationTransition( |
| 82 | + turns: animation3, |
| 83 | + child: CustomPaint( |
| 84 | + painter: Arc3Painter(), |
| 85 | + child: Container( |
| 86 | + width: 50.0, |
| 87 | + height: 50.0, |
| 88 | + ), |
| 89 | + ), |
| 90 | + ) |
| 91 | + ], |
| 92 | + ), |
| 93 | + ); |
| 94 | + } |
| 95 | +} |
| 96 | + |
| 97 | +class Arc1Painter extends CustomPainter { |
| 98 | + |
| 99 | + @override |
| 100 | + void paint(Canvas canvas, Size size) { |
| 101 | + |
| 102 | + Paint p1 = new Paint() |
| 103 | + ..color = Colors.deepOrangeAccent |
| 104 | + ..strokeWidth = 2.0 |
| 105 | + ..strokeCap = StrokeCap.round |
| 106 | + ..style = PaintingStyle.stroke; |
| 107 | + |
| 108 | + Rect rect1 = new Rect.fromLTWH(0.0, 0.0, size.width, size.height); |
| 109 | + |
| 110 | + canvas.drawArc(rect1, 0.0 , 0.5 * pi, false, p1); |
| 111 | + canvas.drawArc(rect1, 0.6 * pi , 0.8 * pi, false, p1); |
| 112 | + canvas.drawArc(rect1, 1.5 * pi , 0.4 * pi, false, p1); |
| 113 | + } |
| 114 | + |
| 115 | + @override |
| 116 | + bool shouldRepaint(CustomPainter oldDelegate) { |
| 117 | + return true; |
| 118 | + } |
| 119 | + |
| 120 | +} |
| 121 | + |
| 122 | +class Arc2Painter extends CustomPainter { |
| 123 | + |
| 124 | + @override |
| 125 | + void paint(Canvas canvas, Size size) { |
| 126 | + |
| 127 | + Paint p2 = new Paint() |
| 128 | + ..color = Colors.yellow |
| 129 | + ..strokeWidth = 2.0 |
| 130 | + ..strokeCap = StrokeCap.round |
| 131 | + ..style = PaintingStyle.stroke; |
| 132 | + |
| 133 | + Rect rect2 = new Rect.fromLTWH(0.0 + (0.2 * size.width)/2, 0.0 + (0.2 * size.height)/2, size.width - 0.2 * size.width, size.height - 0.2 * size.height); |
| 134 | + |
| 135 | + canvas.drawArc(rect2, 0.0 , 0.5 * pi, false, p2); |
| 136 | + canvas.drawArc(rect2, 0.8 * pi , 0.6 * pi, false, p2); |
| 137 | + canvas.drawArc(rect2, 1.6 * pi , 0.2 * pi, false, p2); |
| 138 | + } |
| 139 | + |
| 140 | + @override |
| 141 | + bool shouldRepaint(CustomPainter oldDelegate) { |
| 142 | + return true; |
| 143 | + } |
| 144 | + |
| 145 | +} |
| 146 | + |
| 147 | +class Arc3Painter extends CustomPainter { |
| 148 | + |
| 149 | + @override |
| 150 | + void paint(Canvas canvas, Size size) { |
| 151 | + |
| 152 | + Paint p3 = new Paint() |
| 153 | + ..color = Colors.lightGreen |
| 154 | + ..strokeWidth = 1.5 |
| 155 | + ..strokeCap = StrokeCap.round |
| 156 | + ..style = PaintingStyle.stroke; |
| 157 | + |
| 158 | + Rect rect3 = new Rect.fromLTWH(0.0 + (0.4 * size.width)/2, 0.0 + (0.4 * size.height)/2, size.width - 0.4 * size.width, size.height - 0.4 * size.height); |
| 159 | + |
| 160 | + canvas.drawArc(rect3, 0.0 , 0.9 * pi, false, p3); |
| 161 | + canvas.drawArc(rect3, 1.1 * pi , 0.8 * pi, false, p3); |
| 162 | + } |
| 163 | + |
| 164 | + @override |
| 165 | + bool shouldRepaint(CustomPainter oldDelegate) { |
| 166 | + return true; |
| 167 | + } |
| 168 | + |
| 169 | +} |
0 commit comments