toSafeInt method

int toSafeInt({
  1. int? minValue,
  2. int? maxValue,
})

toInt() clamped to minValue/maxValue. 150.7.toSafeInt(maxValue: 100) → 100

Implementation

int toSafeInt({int? minValue, int? maxValue}) {
  if (minValue != null && this < minValue) return minValue;
  if (maxValue != null && this > maxValue) return maxValue;
  return toInt();
}