validateStringLength function

void validateStringLength(
  1. String? name,
  2. String? value,
  3. int? min,
  4. int? max, {
  5. bool isRequired = false,
})

Implementation

void validateStringLength(
  String? name,
  String? value,
  int? min,
  int? max, {
  bool isRequired = false,
}) {
  if (value == null && !isRequired) return;

  ArgumentError.checkNotNull(value, name);
  ArgumentError.checkNotNull(min, 'min');
  ArgumentError.checkNotNull(max, 'max');
  if ((min! > value!.length || value.length > max!)) {
    throw ArgumentError.value(
      value,
      name,
      '"$name" is either longer than $max or shorter than $min',
    );
  }
}