getPreferredRect method

Rect getPreferredRect(
  1. RenderBox parentBox,
  2. SfSliderThemeData themeData,
  3. Offset offset, {
  4. bool? isActive,
})

Returns the size based on the values passed to it.

Implementation

Rect getPreferredRect(
    RenderBox parentBox, SfSliderThemeData themeData, Offset offset,
    {bool? isActive}) {
  final Size overlayPreferredSize = (parentBox as RenderBaseSlider)
      .overlayShape
      .getPreferredSize(themeData);
  final Size thumbPreferredSize =
      parentBox.thumbShape.getPreferredSize(themeData);
  final Size tickPreferredSize =
      parentBox.tickShape.getPreferredSize(themeData);
  double maxRadius;
  if (_isVertical(parentBox)) {
    maxRadius = math.max(
        overlayPreferredSize.height / 2,
        math.max(
            thumbPreferredSize.height / 2, tickPreferredSize.height / 2));
  } else {
    maxRadius = math.max(overlayPreferredSize.width / 2,
        math.max(thumbPreferredSize.width / 2, tickPreferredSize.width / 2));
  }
  final double maxTrackHeight =
      math.max(themeData.activeTrackHeight, themeData.inactiveTrackHeight);
  // ignore: avoid_as
  if (_isVertical(parentBox)) {
    double left = offset.dx;
    if (isActive != null) {
      left += isActive
          ? (maxTrackHeight - themeData.activeTrackHeight) / 2
          : (maxTrackHeight - themeData.inactiveTrackHeight) / 2;
    }
    final double right = left +
        (isActive == null
            ? maxTrackHeight
            : (isActive
                ? themeData.activeTrackHeight
                : themeData.inactiveTrackHeight));
    final double top = offset.dy + maxRadius;
    final double bottom = top + parentBox.size.height - (2 * maxRadius);
    return Rect.fromLTRB(
        math.min(left, right), top, math.max(left, right), bottom);
  } else {
    final double left = offset.dx + maxRadius;
    double top = offset.dy;
    if (isActive != null) {
      top += isActive
          ? (maxTrackHeight - themeData.activeTrackHeight) / 2
          : (maxTrackHeight - themeData.inactiveTrackHeight) / 2;
    }
    final double right = left + parentBox.size.width - (2 * maxRadius);
    final double bottom = top +
        (isActive == null
            ? maxTrackHeight
            : (isActive
                ? themeData.activeTrackHeight
                : themeData.inactiveTrackHeight));
    return Rect.fromLTRB(
        math.min(left, right), top, math.max(left, right), bottom);
  }
}