interpolateBestDouble static method

double interpolateBestDouble(
  1. InterpolationDoubleValues values,
  2. double currentScreenWidth, {
  3. bool invertedLogic = false,
})

Interpolates a value between a minimum and maximum range based on the screen width. Optionally inverts the logic, returning higher values for smaller widths and lower values for larger widths if invertedLogic is set to true.

  • values: An InterpolationDoubleValues object containing the min, max, minWidth, and maxWidth values.
  • currentScreenWidth: The current width of the screen.
  • invertedLogic: A boolean flag that reverses the interpolation logic if set to true.

Returns the interpolated value.

Implementation

static double interpolateBestDouble(
    InterpolationDoubleValues values, double currentScreenWidth, {bool invertedLogic = false}) {
  double interpolatedValue;

  if (invertedLogic) {
    // Invert the logic: smaller screen width returns higher values and vice versa
    interpolatedValue = values.max -
        (values.max - values.min) *
            (currentScreenWidth - values.minWidth) /
            (values.maxWidth - values.minWidth);
  } else {
    // Normal interpolation: smaller screen width returns lower values
    interpolatedValue = values.min +
        (values.max - values.min) *
            (currentScreenWidth - values.minWidth) /
            (values.maxWidth - values.minWidth);
  }

  // Ensure the interpolated value stays within the range of [min, max]
  return interpolatedValue.clamp(values.min, values.max);
}