getPreferredRect method

Rect getPreferredRect ({@required RenderBox parentBox, Offset offset:, @required SliderThemeData sliderTheme, bool isEnabled: false, bool isDiscrete: false })

Returns a rect that represents the track bounds that fits within the Slider.

The width is the width of the Slider or RangeSlider, but padded by the max of the overlay and thumb radius. The height is defined by the SliderThemeData.trackHeight.

The Rect is centered both horizontally and vertically within the slider bounds.


Rect getPreferredRect({
  @required RenderBox parentBox,
  Offset offset =,
  @required SliderThemeData sliderTheme,
  bool isEnabled = false,
  bool isDiscrete = false,
}) {
  assert(isEnabled != null);
  assert(isDiscrete != null);
  assert(parentBox != null);
  assert(sliderTheme != null);
  final double thumbWidth = sliderTheme.thumbShape.getPreferredSize(isEnabled, isDiscrete).width;
  final double overlayWidth = sliderTheme.overlayShape.getPreferredSize(isEnabled, isDiscrete).width;
  final double trackHeight = sliderTheme.trackHeight;
  assert(overlayWidth >= 0);
  assert(trackHeight >= 0);
  assert(parentBox.size.width >= overlayWidth);
  assert(parentBox.size.height >= trackHeight);

  final double trackLeft = offset.dx + overlayWidth / 2;
  final double trackTop = offset.dy + (parentBox.size.height - trackHeight) / 2;
  final double trackWidth = parentBox.size.width - math.max(thumbWidth, overlayWidth);
  return Rect.fromLTWH(trackLeft, trackTop, trackWidth, trackHeight);