import 'package:flutter/material.dart';

class ZoomAnnotationsWidget extends StatefulWidget {
  @override
  _ZoomAnnotationsWidgetState createState() => _ZoomAnnotationsWidgetState();
}

class _ZoomAnnotationsWidgetState extends State<ZoomAnnotationsWidget> {
  double _scale = 1.0;

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onScaleUpdate: (ScaleUpdateDetails details) {
        setState(() {
          _scale = details.scale;
        });
      },
      child: Container(
        height: double.infinity,
        width: double.infinity,
        child: CustomPaint(
          painter: AnnotationsPainter(_scale),
        ),
      ),
    );
  }
}

class AnnotationsPainter extends CustomPainter {
  final double scale;

  AnnotationsPainter(this.scale);

  @override
  void paint(Canvas canvas, Size size) {
    // Calculate the scaled height based on the scale factor
    double scaledHeight = size.height * scale;

    Paint paint = Paint()
      ..color = Colors.red
      ..strokeWidth = 3.0
      ..strokeCap = StrokeCap.round;

    canvas.drawLine(Offset(0, 0), Offset(size.width, scaledHeight), paint);
  }

  @override
  bool shouldRepaint(covariant CustomPainter oldDelegate) {
    return true;
  }
}
