validStockCount static method

Map<String, dynamic>? validStockCount(
  1. AbstractControl control
)

Validates that the control's value is a valid stock count. The value must be a non-negative integer less than or equal to 10000.

Implementation

static Map<String, dynamic>? validStockCount(
  AbstractControl<dynamic> control,
) {
  if (control.value == null || control.value.toString().isEmpty) {
    return {'required': true};
  }

  var parsed = int.tryParse(control.value) ?? 0;
  if (parsed < 0) {
    return {'min': true};
  } else if (parsed > 10000) {
    return {'max': true};
  }

  return null;
}