drawPointer method

void drawPointer(
  1. PointerShape? shape,
  2. Canvas canvas,
  3. LinearGauge linearGauge,
  4. Offset offset,
)

Method to draw the pointer on the canvas based on the pointer shape

Implementation

void drawPointer(PointerShape? shape, Canvas canvas, LinearGauge linearGauge,
    Offset offset) {
  if (linearGauge.gaugeOrientation == GaugeOrientation.horizontal) {
    if (pointerPosition != PointerPosition.bottom &&
        pointerPosition != PointerPosition.center &&
        pointerPosition != PointerPosition.top) {
      throw ArgumentError(
          'Invalid pointer position: $pointerPosition. For a horizontal gauge, pointer should be positioned at top, bottom, or center.');
    }
  } else {
    if (pointerPosition != PointerPosition.left &&
        pointerPosition != PointerPosition.center &&
        pointerPosition != PointerPosition.right) {
      throw ArgumentError(
          'Invalid pointer position: $pointerPosition. For a vertical gauge, pointer should be positioned at left, right, or center.');
    }
  }

  RulerPosition rulerPosition = linearGauge.rulers!.rulerPosition!;
  switch (shape) {
    case PointerShape.circle:
      _drawCircle(canvas, offset, linearGauge);

      break;
    case PointerShape.rectangle:
      _drawRectangle(canvas, offset, linearGauge);

      break;
    case PointerShape.triangle:
      _drawTriangle(canvas, offset, linearGauge);
      break;
    case PointerShape.diamond:
      _drawDiamond(canvas, offset, linearGauge);
      break;
    default:
      return;
  }

  if (showLabel) {
    _drawLabel(canvas, offset, quarterTurns, rulerPosition, linearGauge);
  }
}