paint method

  1. @override
void paint(
  1. Canvas canvas,
  2. Size size,
  3. WorldToScreen worldToScreen,
  4. ScreenToWorld screenToWorld,
  5. double scale,
)
override

Called by the canvas to paint this item onto the screen.

The canvas and size are provided by the Flutter framework. Use worldToScreen to translate mathematical coordinates into on-screen pixels.

Implementation

@override
void paint(
  Canvas canvas,
  Size size,
  WorldToScreen worldToScreen,
  ScreenToWorld screenToWorld,
  double scale,
) {
  if (vertices.length < 2) return;
  final mappedPoints =
      vertices.map((v) => worldToScreen(v.$1, v.$2)).toList();
  final polygonPath = Path()..moveTo(mappedPoints[0].dx, mappedPoints[0].dy);
  for (int i = 1; i < mappedPoints.length; i++) {
    polygonPath.lineTo(mappedPoints[i].dx, mappedPoints[i].dy);
  }
  polygonPath.close();

  if (fillColor != null) {
    canvas.drawPath(polygonPath, Paint()..color = fillColor!);
  }
  canvas.drawPath(
    polygonPath,
    Paint()
      ..color = strokeColor
      ..strokeWidth = strokeWidth
      ..style = PaintingStyle.stroke
      ..strokeJoin = StrokeJoin.round,
  );
}