import 'package:flutter/material.dart' hide TextStyle;
import 'package:segmentation_douglas_peucker_flutter/dali_point.dart';

class SketcherLine extends CustomPainter {
  SketcherLine({
    required this.points,
  });

  final List<DaliPoint> points;

  @override
  void paint(Canvas canvas, Size size) {
    final Paint paint = Paint()
      ..style = PaintingStyle.stroke
      ..strokeWidth = 10;

    // Set the paint options.
    paint.color = Colors.blue;

    final path = Path();

    if (points.isEmpty) {
      return;
    }

    // Otherwise, draw a line that connects each point with a curve.
    path.moveTo(
      points[0].x.toDouble(),
      points[0].y.toDouble(),
    );

    for (int i = 0; i < points.length; i++) {
      path.lineTo(
        points[i].x.toDouble(),
        points[i].y.toDouble(),
      );
    }

    canvas.drawPath(path, paint);
  }

  @override
  bool shouldRepaint(SketcherLine oldDelegate) => true;
}
