getPreferredRect method

Rect getPreferredRect({
  1. required RenderBox parentBox,
  2. Offset offset = Offset.zero,
  3. required SliderThemeData sliderTheme,
  4. bool isEnabled = false,
  5. bool isDiscrete = false,
})
override

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

Rect getPreferredRect({
  required RenderBox parentBox,
  Offset offset = Offset.zero,
  required SliderThemeData sliderTheme,
  bool isEnabled = false,
  bool isDiscrete = false,
}) {
  final double trackHeight = sliderTheme.trackHeight!;
  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);
}