interpolateBestDouble static method
- InterpolationDoubleValues values,
- double currentScreenWidth, {
- 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: AnInterpolationDoubleValuesobject 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);
}