import 'package:flutter/material.dart';

class SliderWidget extends StatelessWidget {
  final double minValue;
  final double maxValue;
  final double value;
  final Function(double) onChanged;

  const SliderWidget({super.key, required this.minValue, required this.maxValue, required this.value, required this.onChanged});

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.symmetric(horizontal: 8),
      child: SliderTheme(
        data: const SliderThemeData(
          trackShape: CustomSliderTrackShape(),
        ),
        child: Slider(
          min: minValue,
          max: maxValue,
          value: value,
          onChanged: onChanged,
        ),
      ),
    );
  }
}

class CustomSliderTrackShape extends RoundedRectSliderTrackShape {
  const CustomSliderTrackShape();

  @override
  Rect getPreferredRect({
    required RenderBox parentBox,
    Offset offset = Offset.zero,
    required SliderThemeData sliderTheme,
    bool isEnabled = false,
    bool isDiscrete = false,
  }) {
    final trackHeight = sliderTheme.trackHeight;
    final trackLeft = offset.dx;
    final trackTop = offset.dy + (parentBox.size.height - trackHeight!) / 2;
    final trackWidth = parentBox.size.width;
    return Rect.fromLTWH(trackLeft, trackTop, trackWidth, trackHeight);
  }
}
