1
1
part of multi_slice_progress_indicator;
2
2
3
- abstract class ProgressAnimation extends ProxyAnimation {
4
-
3
+ abstract class ProgressAnimation extends ProxyAnimation {
5
4
ProgressAnimation ([super .animation]);
6
5
7
6
double of (int sliceIndex);
8
7
double ofInnerSlice ();
9
8
double ofMiddleSlice ();
10
9
double ofOutterSlice ();
11
-
12
10
}
13
11
14
- class CurvedProgressAnimation extends ProgressAnimation {
15
-
12
+ class CurvedProgressAnimation extends ProgressAnimation {
16
13
CurvedProgressAnimation ({
17
14
Animation <double > parent = kAlwaysDismissedAnimation,
18
15
Curve innerSliceCurve = _defaultInnerSliceAnimationCurve,
@@ -27,7 +24,7 @@ class CurvedProgressAnimation extends ProgressAnimation{
27
24
final Curve _innerSliceCurve;
28
25
final Curve _middleSliceCurve;
29
26
final Curve _outterSliceCurve;
30
-
27
+
31
28
@override
32
29
double of (int sliceIndex) => _values[sliceIndex];
33
30
@@ -47,7 +44,7 @@ class CurvedProgressAnimation extends ProgressAnimation{
47
44
}
48
45
49
46
void _updateValues () {
50
- if (_isReversing)
47
+ if (_isReversing)
51
48
_updateValuesWithFlippedCurves ();
52
49
else
53
50
_updateValuesWithCurves ();
@@ -72,23 +69,22 @@ class CurvedProgressAnimation extends ProgressAnimation{
72
69
}
73
70
}
74
71
75
-
76
72
class ProgressController {
77
-
78
73
ProgressController ({
79
74
required TickerProvider vsync,
80
75
Duration forewardAnimationDuration = _defaultForewardAnimationDuration,
81
76
Duration reverseAnimationDuration = _defaultReverseAnimationDuration,
82
77
Duration completeAnimationDuration = _defaultCompleteAnimationDuration,
83
- }) : _animationController = AnimationController (vsync: vsync,),
78
+ }) : _animationController = AnimationController (
79
+ vsync: vsync,
80
+ ),
84
81
_forewardAnimationDuration = forewardAnimationDuration,
85
82
_reverseAnimationDuration = reverseAnimationDuration,
86
83
_completeAnimationDuration = completeAnimationDuration,
87
84
_startAngleProxyAnimation = CurvedProgressAnimation (),
88
85
_successColorsOpacityProxyAnimation = CurvedProgressAnimation (),
89
86
_failureColorsOpacityProxyAnimation = CurvedProgressAnimation ();
90
87
91
-
92
88
final AnimationController _animationController;
93
89
final Duration _forewardAnimationDuration;
94
90
final Duration _reverseAnimationDuration;
@@ -99,15 +95,16 @@ class ProgressController {
99
95
ProgressAnimation get startAngle => _startAngleProxyAnimation;
100
96
final ProgressAnimation _startAngleProxyAnimation;
101
97
102
- ProgressAnimation get successColorsOpacity => _successColorsOpacityProxyAnimation;
98
+ ProgressAnimation get successColorsOpacity =>
99
+ _successColorsOpacityProxyAnimation;
103
100
final ProgressAnimation _successColorsOpacityProxyAnimation;
104
101
105
- ProgressAnimation get failureColorsOpacity => _failureColorsOpacityProxyAnimation;
102
+ ProgressAnimation get failureColorsOpacity =>
103
+ _failureColorsOpacityProxyAnimation;
106
104
final ProgressAnimation _failureColorsOpacityProxyAnimation;
107
-
108
105
109
- Future <void > start () async {
110
- if (! _canStart ())
106
+ Future <void > start () async {
107
+ if (! _canStart ())
111
108
return ;
112
109
113
110
_prepareToStart ();
@@ -120,7 +117,7 @@ class ProgressController {
120
117
void _prepareToStart () {
121
118
_runCompeleter = Completer ();
122
119
_updateAnimationDuration (_forewardAnimationDuration);
123
-
120
+
124
121
_startAngleProxyAnimation.parent = _animationController;
125
122
_successColorsOpacityProxyAnimation.parent = kAlwaysDismissedAnimation;
126
123
_failureColorsOpacityProxyAnimation.parent = kAlwaysDismissedAnimation;
@@ -136,9 +133,9 @@ class ProgressController {
136
133
_stopCompleter? .complete ();
137
134
_startAngleProxyAnimation.parent = kAlwaysCompleteAnimation;
138
135
}
139
-
140
- Future <void > completeWithSuccess () async {
141
- if (! _canStop ())
136
+
137
+ Future <void > completeWithSuccess () async {
138
+ if (! _canStop ())
142
139
return ;
143
140
144
141
await stop ();
@@ -156,13 +153,13 @@ class ProgressController {
156
153
_successColorsOpacityProxyAnimation.parent = kAlwaysCompleteAnimation;
157
154
}
158
155
159
- Future <void > completeWithFailure () async {
160
- if (! _canStop ())
156
+ Future <void > completeWithFailure () async {
157
+ if (! _canStop ())
161
158
return ;
162
159
163
160
await stop ();
164
161
_prepareToCompleteWithFailure ();
165
- await _forewardAnimation ();
162
+ await _forewardAnimation ();
166
163
_doAfterCompleteWithFailure ();
167
164
}
168
165
@@ -180,23 +177,23 @@ class ProgressController {
180
177
return _animationController.forward ();
181
178
}
182
179
183
- Future <void > stop () async {
184
- if (! _canStop ())
180
+ Future <void > stop () async {
181
+ if (! _canStop ())
185
182
return ;
186
183
187
184
_runCompeleter! .complete ();
188
185
_stopCompleter = Completer ();
189
-
186
+
190
187
return _stopCompleter! .future;
191
188
}
192
189
193
190
bool _canStop () => ! (_runCompeleter? .isCompleted ?? true );
194
-
195
- Future <void > reverse () async {
196
- if (! _canReverse ())
191
+
192
+ Future <void > reverse () async {
193
+ if (! _canReverse ())
197
194
return ;
198
195
199
- _prepareToReverse ();
196
+ _prepareToReverse ();
200
197
await _reversAnimation ();
201
198
_refresh ();
202
199
}
@@ -209,12 +206,12 @@ class ProgressController {
209
206
_updateAnimationDuration (_reverseAnimationDuration);
210
207
211
208
_startAngleProxyAnimation.parent = _animationController;
212
-
213
- if (_successColorsOpacityProxyAnimation.parent == kAlwaysCompleteAnimation)
209
+
210
+ if (_successColorsOpacityProxyAnimation.parent == kAlwaysCompleteAnimation)
214
211
_successColorsOpacityProxyAnimation.parent = _animationController;
215
-
216
- if (_failureColorsOpacityProxyAnimation.parent == kAlwaysCompleteAnimation)
217
- _failureColorsOpacityProxyAnimation.parent = _animationController;
212
+
213
+ if (_failureColorsOpacityProxyAnimation.parent == kAlwaysCompleteAnimation)
214
+ _failureColorsOpacityProxyAnimation.parent = _animationController;
218
215
}
219
216
220
217
Future <void > _reversAnimation () async {
@@ -226,16 +223,16 @@ class ProgressController {
226
223
_startAngleProxyAnimation.parent = kAlwaysDismissedAnimation;
227
224
_successColorsOpacityProxyAnimation.parent = kAlwaysDismissedAnimation;
228
225
_failureColorsOpacityProxyAnimation.parent = kAlwaysDismissedAnimation;
229
-
226
+
230
227
_runCompeleter = null ;
231
228
_stopCompleter = null ;
232
229
}
233
230
234
- void _updateAnimationDuration (Duration newDuration){
231
+ void _updateAnimationDuration (Duration newDuration) {
235
232
_animationController.duration = newDuration;
236
233
}
237
-
234
+
238
235
void dispose () {
239
236
_animationController.dispose ();
240
237
}
241
- }
238
+ }
0 commit comments