onPaint method

  1. @override
void onPaint(
  1. Canvas canvas
)
override

Draws segment in series bounds.

Implementation

@override
void onPaint(Canvas canvas) {
  if (points.isEmpty || points.length != 2) {
    return;
  }

  final Paint paint = getStrokePaint();
  if (paint.color == Colors.transparent || paint.strokeWidth < 0) {
    return;
  }

  final Offset start;
  final Offset end;
  if (animationFactor < 1) {
    if (series.animationType == AnimationType.realtime &&
        series._hasNewSegmentAdded &&
        !isEmpty &&
        series.dataCount == currentSegmentIndex + 2) {
      final double prevX = _oldPoints[0].dx;
      final double prevY = _oldPoints[0].dy;
      final double x1 = points[0].dx;
      final double y1 = points[0].dy;
      final double x2 = points[1].dx;
      final double y2 = points[1].dy;

      final double newX1 = prevX + (x1 - prevX) * animationFactor;
      final double newY1 = prevY + (y1 - prevY) * animationFactor;
      final double newX2 = newX1 + (x2 - newX1) * animationFactor;
      final double newY2 = newY1 + (y2 - newY1) * animationFactor;

      start = Offset(newX1, newY1);
      end = Offset(newX2, newY2);
    } else {
      start = Offset.lerp(_oldPoints[0], points[0], animationFactor)!;
      end = Offset.lerp(_oldPoints[1], points[1], animationFactor)!;
    }
  } else {
    start = points[0];
    end = points[1];
  }

  if (start.isNaN || end.isNaN) {
    return;
  }
  drawDashes(canvas, series.dashArray, paint, start: start, end: end);
}