drawPreviewLine method

void drawPreviewLine(
  1. Canvas canvas,
  2. Offset startPosition,
  3. Offset endPosition,
  4. DrawingPaintStyle paintStyle,
  5. LineStyle lineStyle, {
  6. bool isDashed = false,
})
inherited

Draws a preview line between two points with optional dashed styling.

This method renders the trend line preview during creation, allowing users to see how the line will appear before finalizing it. The line can be drawn as either solid or dashed based on the platform requirements.

Features:

  • Solid line drawing for desktop hover previews
  • Dashed line drawing for mobile touch previews
  • Consistent styling with the configured line properties
  • Efficient path-based rendering for dashed lines

Parameters:

  • canvas: The canvas to draw on
  • startPosition: Screen coordinate of the line start
  • endPosition: Screen coordinate of the line end
  • paintStyle: Drawing paint configuration
  • lineStyle: Line styling (color, thickness)
  • isDashed: Whether to draw a dashed line (default: false)

Implementation

void drawPreviewLine(
  Canvas canvas,
  Offset startPosition,
  Offset endPosition,
  DrawingPaintStyle paintStyle,
  LineStyle lineStyle, {
  bool isDashed = false,
}) {
  final Paint paint = paintStyle.linePaintStyle(
    lineStyle.color,
    lineStyle.thickness,
  );

  if (isDashed) {
    final Path linePath = Path()
      ..moveTo(startPosition.dx, startPosition.dy)
      ..lineTo(endPosition.dx, endPosition.dy);

    canvas.drawPath(
      dashPath(
        linePath,
        dashArray: CircularIntervalList<double>(<double>[2, 2]),
      ),
      Paint()
        ..color = paint.color
        ..style = PaintingStyle.stroke
        ..strokeWidth = paint.strokeWidth,
    );
  } else {
    canvas.drawLine(startPosition, endPosition, paint);
  }
}