drawPreviewLine method
void
drawPreviewLine(
- Canvas canvas,
- Offset startPosition,
- Offset endPosition,
- DrawingPaintStyle paintStyle,
- LineStyle lineStyle, {
- 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 onstartPosition: Screen coordinate of the line startendPosition: Screen coordinate of the line endpaintStyle: Drawing paint configurationlineStyle: 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);
}
}