You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.3 KiB
Dart
48 lines
1.3 KiB
Dart
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);
|
|
}
|
|
}
|