import 'package:flutter/material.dart';
class HorizSeekbarWidget extends StatelessWidget {
final double height;
final int value;
final ValueChanged<double> onChange;
final ValueChanged<double> onChangeStart;
final ValueChanged<double> onChangeEnd;
const HorizSeekbarWidget(
this.height,
this.value,
this.onChange,
this.onChangeStart,
this.onChangeEnd,
);
@override
Widget build(BuildContext context) {
return SliderTheme(
data: SliderTheme.of(context).copyWith(
trackShape: WDCustomTrackShape(),
trackHeight: height,
activeTrackColor: Colors.red,
inactiveTrackColor: Colors.grey,
thumbShape: const RoundSliderThumbShape(
enabledThumbRadius: 0,
),
thumbColor: Colors.transparent,
overlayColor: Colors.transparent,
overlayShape:
const RoundSliderOverlayShape(overlayRadius: 15),
),
child: Slider(
value: value.toDouble(),
min: 0,
max: 100,
onChanged: onChange,
onChangeStart: onChangeStart,
onChangeEnd: onChangeEnd,
divisions: 100,
),
);
}
}
class WDCustomTrackShape extends RectangularSliderTrackShape {
@override
Rect getPreferredRect({
required RenderBox parentBox,
Offset offset = Offset.zero,
required SliderThemeData sliderTheme,
bool isEnabled = false,
bool isDiscrete = false,
}) {
final double trackHeight = sliderTheme.trackHeight??1;
final double trackLeft = offset.dx;
final double trackTop =
offset.dy + (parentBox.size.height - trackHeight) / 2;
final double trackWidth = parentBox.size.width;
return Rect.fromLTWH(trackLeft, trackTop, trackWidth, trackHeight);
}
}