isInRange<T extends num> function

IValidator isInRange<T extends num>(
  1. T min,
  2. T max, {
  3. String? message,
})

Checks whether the given numeric value is within the range min, max (inclusive).

Implementation

IValidator isInRange<T extends num>(T min, T max, {String? message}) {
  assert(!(min.isNaN) && !(max.isNaN), 'min/max must be valid numbers');
  assert(min <= max, 'min must be <= max');
  return (isNumber() & isGte(min) & isLte(max)) >
      Expectation(
        message: message ?? 'between $min and $max inclusive',
        code: ExpectationCodes.valueRangeOutOfBounds,
        data: {'operator': 'between_inclusive', 'min': min, 'max': max},
      );
}