getPaint static method
Paint
getPaint({
- required Color color,
- double? strokeWidth,
- PaintingStyle? style,
- StrokeCap? strokeCap,
- StrokeJoin? strokeJoin,
- MaskFilter? maskFilter,
Get or create a Paint object
Implementation
static Paint getPaint({
required Color color,
double? strokeWidth,
PaintingStyle? style,
StrokeCap? strokeCap,
StrokeJoin? strokeJoin,
MaskFilter? maskFilter,
}) {
final key =
'paint_${color.toARGB32()}_${strokeWidth}_${style}_${strokeCap}_${strokeJoin}_$maskFilter';
if (_paintCache.containsKey(key)) {
final paint = _paintCache[key]!;
// Update properties if needed
paint.color = color;
if (strokeWidth != null) paint.strokeWidth = strokeWidth;
if (style != null) paint.style = style;
if (strokeCap != null) paint.strokeCap = strokeCap;
if (strokeJoin != null) paint.strokeJoin = strokeJoin;
if (maskFilter != null) paint.maskFilter = maskFilter;
return paint;
}
final paint = Paint()
..color = color
..strokeWidth = strokeWidth ?? 1.0
..style = style ?? PaintingStyle.stroke
..strokeCap = strokeCap ?? StrokeCap.butt
..strokeJoin = strokeJoin ?? StrokeJoin.miter;
if (maskFilter != null) paint.maskFilter = maskFilter;
_paintCache[key] = paint;
return paint;
}