validateNumericConstraints function

void validateNumericConstraints({
  1. num? min,
  2. num? max,
  3. num? step,
})

Validates the shared bounds and step contract for numeric prompts.

Optional bounds must be finite and ordered. An optional step must be finite and greater than zero. A bounded step grid must also have a finite representable span. Invalid constraints throw ArgumentError. This is exposed so prompt implementations can validate their configuration even when they do not have an initial value to normalize.

Implementation

void validateNumericConstraints({
  num? min,
  num? max,
  num? step,
}) {
  _validateFinite(min, 'min');
  _validateFinite(max, 'max');
  _validateFinite(step, 'step');
  if (min != null && max != null && min > max) {
    throw ArgumentError.value(
      max,
      'max',
      'must be greater than or equal to min',
    );
  }
  if (step != null && step <= 0) {
    throw ArgumentError.value(
      step,
      'step',
      'must be finite and greater than 0',
    );
  }
  if (step != null && max != null) {
    final anchor = min ?? 0;
    final maxUnits = (max - anchor) / step;
    if (!maxUnits.isFinite) {
      throw ArgumentError.value(
        step,
        'step',
        'produces an unrepresentable step grid for the supplied bounds',
      );
    }
  }
}