@@ -14,7 +14,9 @@ class LayeredChart extends StatefulWidget {
14
14
final List <WeekLabel > milestones;
15
15
final double animationValue;
16
16
17
- LayeredChart (this .dataToPlot, this .milestones, this .animationValue);
17
+ const LayeredChart (this .dataToPlot, this .milestones, this .animationValue,
18
+ {Key ? key})
19
+ : super (key: key);
18
20
19
21
@override
20
22
State <StatefulWidget > createState () {
@@ -23,14 +25,14 @@ class LayeredChart extends StatefulWidget {
23
25
}
24
26
25
27
class LayeredChartState extends State <LayeredChart > {
26
- List <Path > paths;
27
- List <Path > capPaths;
28
- List <double > maxValues;
29
- double theta;
30
- double graphHeight;
31
- List <TextPainter > labelPainter;
32
- List <TextPainter > milestonePainter;
33
- Size lastSize;
28
+ late List <Path > paths;
29
+ late List <Path > capPaths;
30
+ late List <double > maxValues;
31
+ late double theta;
32
+ late double graphHeight;
33
+ late List <TextPainter > labelPainter;
34
+ late List <TextPainter > milestonePainter;
35
+ Size ? lastSize;
34
36
35
37
void buildPaths (
36
38
Size size,
@@ -89,7 +91,7 @@ class LayeredChartState extends State<LayeredChart> {
89
91
j.toDouble (), 0 , (numPoints - 1 ).toDouble (), 0 , (n - 1 ).toDouble ());
90
92
curve.progressiveGet (cpv);
91
93
curvePoints.add (MathUtils .map (
92
- max (0 , cpv.value), 0 , maxValues[i].toDouble (), 0 , graphHeight));
94
+ max (0 , cpv.value! ), 0 , maxValues[i].toDouble (), 0 , graphHeight));
93
95
}
94
96
paths.add (Path ());
95
97
capPaths.add (Path ());
@@ -136,7 +138,7 @@ class LayeredChartState extends State<LayeredChart> {
136
138
labelPainter = < TextPainter > [];
137
139
for (int i = 0 ; i < dataToPlot.length; i++ ) {
138
140
TextSpan span = TextSpan (
139
- style: TextStyle (
141
+ style: const TextStyle (
140
142
color: Color .fromARGB (255 , 255 , 255 , 255 ), fontSize: 12 ),
141
143
text: dataToPlot[i].label.toUpperCase ());
142
144
TextPainter tp = TextPainter (
@@ -149,7 +151,7 @@ class LayeredChartState extends State<LayeredChart> {
149
151
milestonePainter = < TextPainter > [];
150
152
for (int i = 0 ; i < milestones.length; i++ ) {
151
153
TextSpan span = TextSpan (
152
- style: TextStyle (
154
+ style: const TextStyle (
153
155
color: Color .fromARGB (255 , 255 , 255 , 255 ), fontSize: 10 ),
154
156
text: milestones[i].label.toUpperCase ());
155
157
TextPainter tp = TextPainter (
@@ -174,15 +176,15 @@ class LayeredChartState extends State<LayeredChart> {
174
176
}
175
177
176
178
class ChartPainter extends CustomPainter {
177
- static List <Color > colors = [
179
+ static List <Color ? > colors = [
178
180
Colors .red[900 ],
179
- Color (0xffc4721a ),
181
+ const Color (0xffc4721a ),
180
182
Colors .lime[900 ],
181
183
Colors .green[900 ],
182
184
Colors .blue[900 ],
183
185
Colors .purple[900 ],
184
186
];
185
- static List <Color > capColors = [
187
+ static List <Color ? > capColors = [
186
188
Colors .red[500 ],
187
189
Colors .amber[500 ],
188
190
Colors .lime[500 ],
@@ -196,17 +198,17 @@ class ChartPainter extends CustomPainter {
196
198
197
199
double margin;
198
200
double graphGap;
199
- double capTheta;
201
+ late double capTheta;
200
202
double capSize;
201
203
int numPoints;
202
204
double amount = 1.0 ;
203
205
204
- Paint pathPaint;
205
- Paint capPaint;
206
- Paint textPaint;
207
- Paint milestonePaint;
208
- Paint linePaint;
209
- Paint fillPaint;
206
+ late Paint pathPaint;
207
+ late Paint capPaint;
208
+ late Paint textPaint;
209
+ late Paint milestonePaint;
210
+ late Paint linePaint;
211
+ late Paint fillPaint;
210
212
211
213
LayeredChartState state;
212
214
@@ -220,13 +222,13 @@ class ChartPainter extends CustomPainter {
220
222
this .capSize,
221
223
this .numPoints,
222
224
this .amount) {
223
- this . capTheta = pi * capDegrees / 180 ;
225
+ capTheta = pi * capDegrees / 180 ;
224
226
pathPaint = Paint ();
225
227
pathPaint.style = PaintingStyle .fill;
226
228
capPaint = Paint ();
227
229
capPaint.style = PaintingStyle .fill;
228
230
textPaint = Paint ();
229
- textPaint.color = Color (0xFFFFFFFF );
231
+ textPaint.color = const Color (0xFFFFFFFF );
230
232
milestonePaint = Paint ();
231
233
milestonePaint.color = Constants .milestoneColor;
232
234
milestonePaint.style = PaintingStyle .stroke;
@@ -236,19 +238,19 @@ class ChartPainter extends CustomPainter {
236
238
linePaint.strokeWidth = 0.5 ;
237
239
fillPaint = Paint ();
238
240
fillPaint.style = PaintingStyle .fill;
239
- fillPaint.color = Color (0xFF000000 );
241
+ fillPaint.color = const Color (0xFF000000 );
240
242
}
241
243
242
244
@override
243
245
void paint (Canvas canvas, Size size) {
244
- if (dataToPlot.length == 0 ) {
246
+ if (dataToPlot.isEmpty ) {
245
247
return ;
246
248
}
247
249
248
250
if (state.lastSize == null ||
249
- size.width != state.lastSize.width ||
250
- size.height != state.lastSize.height) {
251
- print (" Building paths, lastsize = ${state .lastSize }" );
251
+ size.width != state.lastSize! .width ||
252
+ size.height != state.lastSize! .height) {
253
+ print (' Building paths, lastsize = ${state .lastSize }' );
252
254
state.buildPaths (size, dataToPlot, milestones, numPoints, graphGap,
253
255
margin, capTheta, capSize);
254
256
}
@@ -266,7 +268,7 @@ class ChartPainter extends CustomPainter {
266
268
{
267
269
for (int i = 0 ; i < milestones.length; i++ ) {
268
270
WeekLabel milestone = milestones[i];
269
- double p = (milestone.weekNum.toDouble () / numWeeks) + (1 - amount);
271
+ double p = (milestone.weekNum! .toDouble () / numWeeks) + (1 - amount);
270
272
if (p < 1 ) {
271
273
double x1 = MathUtils .map (p, 0 , 1 , startX, endX);
272
274
double y1 = MathUtils .map (p, 0 , 1 , startY, endY);
@@ -282,7 +284,7 @@ class ChartPainter extends CustomPainter {
282
284
canvas.translate (textX, textY);
283
285
canvas.skew (tan (capTheta * 1.0 ), - tan (state.theta));
284
286
canvas.translate (- tp.width / 2 , 0 );
285
- tp.paint (canvas, Offset (0 , 0 ));
287
+ tp.paint (canvas, const Offset (0 , 0 ));
286
288
canvas.restore ();
287
289
}
288
290
}
@@ -302,11 +304,11 @@ class ChartPainter extends CustomPainter {
302
304
canvas.skew (0 , - tan (state.theta));
303
305
canvas.drawRect (
304
306
Rect .fromLTWH (- 1 , - 1 , tp.width + 2 , tp.height + 2 ), fillPaint);
305
- tp.paint (canvas, Offset (0 , 0 ));
307
+ tp.paint (canvas, const Offset (0 , 0 ));
306
308
canvas.restore ();
307
309
}
308
310
309
- linePaint.color = capColors[i];
311
+ linePaint.color = capColors[i]! ;
310
312
canvas.drawLine (Offset (startX, startY), Offset (endX, endY), linePaint);
311
313
312
314
Path clipPath = Path ();
@@ -317,8 +319,8 @@ class ChartPainter extends CustomPainter {
317
319
clipPath.close ();
318
320
canvas.clipPath (clipPath);
319
321
320
- pathPaint.color = colors[i];
321
- capPaint.color = capColors[i];
322
+ pathPaint.color = colors[i]! ;
323
+ capPaint.color = capColors[i]! ;
322
324
double offsetX = MathUtils .map (1 - amount, 0 , 1 , startX, endX);
323
325
double offsetY = MathUtils .map (1 - amount, 0 , 1 , startY, endY);
324
326
canvas.translate (offsetX - startX, offsetY - startY);
0 commit comments