isInRange method

bool isInRange(
  1. int min,
  2. int max, {
  3. bool inclusive = true,
})

Checks if the int value is within the specified range.

Determines if this int is between min and max.

  • If inclusive is true, the range is inclusive, meaning the method returns true if the value is equal to min or max.
  • If inclusive is false, the range is exclusive, meaning the method returns true only if the value is strictly between min and max.

Parameters:

  • min: The lower bound of the range.
  • max: The upper bound of the range.
  • inclusive: A boolean indicating whether the range is inclusive. Defaults to true.

Returns:

  • true if the int is within the specified range, according to the inclusive flag.
  • false otherwise.

Implementation

bool isInRange(int min, int max, {bool inclusive = true}) {
  assert(min <= max);
  if (inclusive) {
    return this >= min && this <= max;
  } else {
    return this > min && this < max;
  }
}