drawRect method
The rectangle rendering of a plotband, based on the start and end values defined.
Allows complete customization of the plot band custom shapes appearance using canvas drawing operations.
Custom visuals such as gradients, patterns, textures, borders, and transparency effects can be implemented.
rect defines the plot band rendering bounds.
Example – render a rectangle with corner radius:
class CustomPlotBand extends PlotBand {
@override
void drawRect(
Canvas canvas,
Rect rect,
Paint fillPaint, [
Paint? strokePaint,
]) {
canvas.drawRRect(
RRect.fromRectAndRadius(rect, const Radius.circular(8)),
fillPaint,
);
}
}
Implementation
void drawRect(
Canvas canvas,
Rect rect,
Paint fillPaint, [
Paint? strokePaint,
]) {
if (fillPaint.color != Colors.transparent && rect.width != 0.0) {
canvas.drawRect(rect, fillPaint);
}
if (strokePaint != null &&
strokePaint.strokeWidth > 0 &&
strokePaint.color != Colors.transparent) {
final double left = rect.left;
final double top = rect.top;
final double width = rect.width;
final double height = rect.height;
final Path path =
Path()
..moveTo(left, top)
..lineTo(left + width, top)
..lineTo(left + width, top + height)
..lineTo(left, top + height)
..close();
drawDashes(canvas, dashArray, strokePaint, path: path);
}
}