checkValueInInterval method

int checkValueInInterval (
  1. int value,
  2. int minValue,
  3. int maxValue,
  4. [String? name,
  5. String? message]
)

Check that an integer value lies in a specific interval.

Throws if value is not in the interval. The interval is from minValue to maxValue, both inclusive.

If name or message are provided, they are used as the parameter name and message text of the thrown error.

Returns value if it is in the interval.

Implementation

static int checkValueInInterval(int value, int minValue, int maxValue,
    [String? name, String? message]) {
  if (value < minValue || value > maxValue) {
    throw RangeError.range(value, minValue, maxValue, name, message);
  }
  return value;
}

© 2012 the Dart project authors
Licensed under the Creative Commons Attribution-ShareAlike License v4.0.
https://api.dart.dev/stable/2.13.0/dart-core/RangeError/checkValueInInterval.html