getPreferredRect method
- required RenderBox parentBox,
- Offset offset = Offset.zero,
- SliderThemeData? sliderTheme,
- bool isEnabled = false,
- bool isDiscrete = false,
Returns the preferred bounds of the shape.
It is used to provide horizontal boundaries for the thumb's position, and to help position the slider thumb and tick marks relative to the track.
The parentBox
argument can be used to help determine the preferredRect relative to
attributes of the render box of the slider itself, such as size.
The offset
argument is relative to the caller's bounding box. It can be used to
convert gesture coordinates from global to slider-relative coordinates.
the sliderTheme
argument is the theme assigned to the Slider that this
shape belongs to.
The isEnabled
argument is false when Slider.onChanged is null and true
otherwise. When true, the slider will respond to input.
The isDiscrete
argument is true if Slider.divisions is non-null. When
true, the slider will render tick marks on top of the track.
Implementation
@override
Rect getPreferredRect({
required RenderBox parentBox,
Offset offset = Offset.zero,
SliderThemeData? sliderTheme,
bool isEnabled = false,
bool isDiscrete = false,
}) {
const double trackHeight = 1;
final double trackLeft = offset.dx;
final double trackTop =
offset.dy + (parentBox.size.height - trackHeight) / 2 + 4;
final double trackWidth = parentBox.size.width;
return Rect.fromLTWH(trackLeft, trackTop, trackWidth, trackHeight);
}