draw method

  1. @override
void draw(
  1. Canvas canvas,
  2. Size boardSize
)
override

Implementation

@override
void draw(Canvas canvas, Size boardSize) {
  /// Draw the line shape on the canvas
  final Paint paint = Paint()
    ..color = color
    ..strokeWidth = size.height
    ..style = style;

  Path path = Path();
  path.moveTo(location.dx, location.dy);
  path.lineTo(_endOffset.dx, _endOffset.dy);
  canvas.drawPath(path, paint);

  /// Highlight or select the line shape if necessary
  if (isHighlight || isSelected) {
    paint.color = Colors.blue;
    paint.style = PaintingStyle.stroke;
    canvas.drawPath(path, paint);
  }

  /// Draw resize points and remove points if the line shape is selected
  if (isSelected) {
    for (var resizePoint in resizePoints) {
      paint.color = Colors.blue;
      paint.style = PaintingStyle.fill;
      canvas.drawCircle(
        Offset(resizePoint.offset.dx, resizePoint.offset.dy),
        5,
        paint,
      );
    }
    for (var removePoint in removePoints) {
      const icon = Icons.remove_circle;
      TextPainter textPainter = TextPainter(textDirection: TextDirection.ltr);
      textPainter.text = TextSpan(
        text: String.fromCharCode(icon.codePoint),
        style: TextStyle(
          color: Colors.red,
          fontSize: 20,
          fontFamily: icon.fontFamily,
          package: icon.fontPackage,
        ),
      );
      textPainter.layout();
      textPainter.paint(canvas, removePoint.translate(-10, -10));
    }
  }
}