import 'package:flutter/material.dart';

class LineChartPainter extends CustomPainter {
  final List<double> data;

  LineChartPainter(this.data);

  @override
  void paint(Canvas canvas, Size size) {
    // Calculate the scale factor.
    final scaleFactor = size.height / 240;

    // Draw the line chart.
    for (var i = 0; i < data.length - 1; i++) {
      final x1 = i * size.width / data.length;
      final y1 = data[i] * scaleFactor;
      final x2 = (i + 1) * size.width / data.length;
      final y2 = data[i + 1] * scaleFactor;

      canvas.drawLine(Offset(x1, y1), Offset(x2, y2), Paint());
    }
  }

  @override
  bool shouldRepaint(LineChartPainter oldDelegate) => false;
}
