@@ -69,10 +69,10 @@ class PolylineLayer extends StatelessWidget {
69
69
final bool saveLayers;
70
70
71
71
const PolylineLayer ({
72
- super .key,
73
- this .polylines = const [],
74
- this .polylineCulling = false ,
75
- this .saveLayers = false ,
72
+ super .key,
73
+ this .polylines = const [],
74
+ this .polylineCulling = false ,
75
+ this .saveLayers = false ,
76
76
});
77
77
78
78
@override
@@ -82,8 +82,8 @@ class PolylineLayer extends StatelessWidget {
82
82
83
83
final List <Polyline > lines = polylineCulling
84
84
? polylines.where ((p) {
85
- return p.boundingBox.isOverlapping (map.bounds);
86
- }).toList ()
85
+ return p.boundingBox.isOverlapping (map.bounds);
86
+ }).toList ()
87
87
: polylines;
88
88
89
89
return CustomPaint (
@@ -141,9 +141,7 @@ class PolylinePainter extends CustomPainter {
141
141
int ? lastHash;
142
142
143
143
void drawPaths () {
144
- canvas.drawPath (path, paint);
145
- path = ui.Path ();
146
- paint = Paint ();
144
+ if (saveLayers) canvas.saveLayer (rect, Paint ());
147
145
148
146
if (borderPaint != null ) {
149
147
canvas.drawPath (borderPath, borderPaint! );
@@ -156,6 +154,12 @@ class PolylinePainter extends CustomPainter {
156
154
filterPath = ui.Path ();
157
155
filterPaint = null ;
158
156
}
157
+
158
+ canvas.drawPath (path, paint);
159
+ path = ui.Path ();
160
+ paint = Paint ();
161
+
162
+ if (saveLayers) canvas.restore ();
159
163
}
160
164
161
165
for (final polyline in polylines) {
@@ -165,7 +169,7 @@ class PolylinePainter extends CustomPainter {
165
169
}
166
170
167
171
final hash = polyline.renderHashCode;
168
- if (lastHash != null && lastHash != hash) {
172
+ if (saveLayers || ( lastHash != null && lastHash != hash) ) {
169
173
drawPaths ();
170
174
}
171
175
lastHash = hash;
@@ -225,7 +229,6 @@ class PolylinePainter extends CustomPainter {
225
229
final radius = paint.strokeWidth / 2 ;
226
230
final borderRadius = (borderPaint? .strokeWidth ?? 0 ) / 2 ;
227
231
228
- if (saveLayers) canvas.saveLayer (rect, Paint ());
229
232
if (isDotted) {
230
233
final spacing = strokeWidth * 1.5 ;
231
234
if (borderPaint != null && filterPaint != null ) {
@@ -240,7 +243,6 @@ class PolylinePainter extends CustomPainter {
240
243
}
241
244
_paintLine (path, offsets);
242
245
}
243
- if (saveLayers) canvas.restore ();
244
246
}
245
247
246
248
drawPaths ();
@@ -281,16 +283,16 @@ class PolylinePainter extends CustomPainter {
281
283
282
284
List <double >? _getColorsStop (Polyline polyline) =>
283
285
(polyline.colorsStop != null &&
284
- polyline.colorsStop! .length == polyline.gradientColors! .length)
286
+ polyline.colorsStop! .length == polyline.gradientColors! .length)
285
287
? polyline.colorsStop
286
288
: _calculateColorsStop (polyline);
287
289
288
290
List <double > _calculateColorsStop (Polyline polyline) {
289
291
final colorsStopInterval = 1.0 / polyline.gradientColors! .length;
290
292
return polyline.gradientColors!
291
293
.map ((gradientColor) =>
292
- polyline.gradientColors! .indexOf (gradientColor) *
293
- colorsStopInterval)
294
+ polyline.gradientColors! .indexOf (gradientColor) *
295
+ colorsStopInterval)
294
296
.toList ();
295
297
}
296
298
@@ -301,4 +303,4 @@ class PolylinePainter extends CustomPainter {
301
303
oldDelegate.polylines.length != polylines.length ||
302
304
oldDelegate.hash != hash;
303
305
}
304
- }
306
+ }
0 commit comments