import 'dart:ui';

import 'package:flutter/cupertino.dart';

class SCHollowCircle extends StatelessWidget {
  final double size;
  final double strokeWidth;
  final Gradient gradient;

  const SCHollowCircle({
    super.key,
    required this.size,
    this.strokeWidth = 3.0,
    required this.gradient,
  });

  @override
  Widget build(BuildContext context) {
    return CustomPaint(
      size: Size(size, size),
      painter: _HollowCirclePainter(
        strokeWidth: strokeWidth,
        gradient: gradient,
      ),
    );
  }
}

class _HollowCirclePainter extends CustomPainter {
  final double strokeWidth;
  final Gradient gradient;

  _HollowCirclePainter({
    required this.strokeWidth,
    required this.gradient,
  });

  @override
  void paint(Canvas canvas, Size size) {
    final center = Offset(size.width / 2, size.height / 2);
    final radius = size.width / 2 - strokeWidth / 2;

    final paint = Paint()
      ..shader = gradient.createShader(Rect.fromCircle(
        center: center,
        radius: radius,
      ))
      ..strokeWidth = strokeWidth
      ..style = PaintingStyle.stroke
      ..strokeCap = StrokeCap.round;

    canvas.drawCircle(center, radius, paint);
  }

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