Skip to content

Commit cbb9c61

Browse files
authored
Add files via upload
1 parent b09dbc7 commit cbb9c61

File tree

1 file changed

+104
-0
lines changed

1 file changed

+104
-0
lines changed

lib/Progress.dart

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
import 'dart:async';
2+
3+
import 'package:flutter/material.dart';
4+
import 'package:flutter/widgets.dart';
5+
6+
class MyProgress extends StatefulWidget {
7+
final Size size;
8+
final Color color;
9+
final int count;
10+
final int milliseconds;
11+
12+
const MyProgress({@required this.size, this.milliseconds: 300, this.color: Colors
13+
.green, this.count: 4});
14+
15+
@override
16+
State<StatefulWidget> createState() => _ProgressState();
17+
18+
}
19+
20+
class _ProgressState extends State<MyProgress> with TickerProviderStateMixin {
21+
22+
List<Animation<double>>animators = [];
23+
List<AnimationController>_animationControllers = [];
24+
25+
@override
26+
void initState() {
27+
super.initState();
28+
for (int i = 0; i < widget.count; i++) {
29+
30+
var animationController = new AnimationController(vsync: this,
31+
duration: Duration(milliseconds: widget.milliseconds * widget.count));
32+
animationController.value=0.8*i/widget.count;
33+
_animationControllers.add(animationController);
34+
Animation<double> animation = new Tween(begin: 0.1, end: 1.9).animate(
35+
animationController);
36+
animators.add(animation);
37+
}
38+
animators[0].addListener(_change);
39+
try {
40+
var mi = (widget.milliseconds~/(2*animators.length-2));
41+
for (int i = 0; i < animators.length; i++) {
42+
print(( mi*i).toString());
43+
dodelay(_animationControllers[i], mi*i);
44+
}
45+
} on Exception {
46+
47+
}
48+
}
49+
50+
void dodelay(AnimationController _animationControllers,
51+
int delay) async{
52+
Future.delayed(Duration(milliseconds: delay),(){
53+
_animationControllers..repeat().orCancel;
54+
});
55+
}
56+
57+
void _change() {
58+
setState(() {});
59+
}
60+
61+
@override
62+
Widget build(BuildContext context) {
63+
return new CustomPaint(painter: _Progress(
64+
animators: animators, color: widget.color, count: widget.count),
65+
size: widget.size,);
66+
}
67+
68+
@override
69+
void dispose() {
70+
super.dispose();
71+
animators[0].removeListener(_change);
72+
for (AnimationController _animationController in _animationControllers) {
73+
_animationController.dispose();
74+
}
75+
}
76+
}
77+
78+
class _Progress extends CustomPainter {
79+
final Color color;
80+
final int count;
81+
final List<Animation<double>>animators;
82+
83+
const _Progress({this.animators, this.color, this.count});
84+
85+
@override
86+
void paint(Canvas canvas, Size size) {
87+
var radius = size.width / (3 * count + 1);
88+
var paint = new Paint()
89+
..color = color
90+
..style = PaintingStyle.fill;
91+
for (int i = 1; i < count + 1; i++) {
92+
double value = animators[i - 1].value;
93+
canvas.drawCircle(
94+
new Offset(radius * i * 3 - radius, size.height / 2),
95+
radius * (value > 1 ? (2 - value) : value), paint);
96+
}
97+
}
98+
99+
@override
100+
bool shouldRepaint(CustomPainter oldDelegate) {
101+
return oldDelegate != this;
102+
}
103+
104+
}

0 commit comments

Comments
 (0)