lengthIsInRange method
lengthIsInRange compares the length of a string to the minLength and maxLength
to ensure it is between the given values.
Provides a basic error message that can be used.
'valueName must be between minLength and maxLength characters long.'
A return value of null indicates a valid length.
thows an ArgumentError if valueName is null or the String value is null.
Implementation
String? lengthIsInRange({
int? minLength = 0,
int? maxLength = 25,
String? valueName,
}) {
if (this == null) {
throw ArgumentError('value is required', this);
}
return this!.length < minLength! || this!.length > maxLength!
? '$valueName must be between $minLength and $maxLength characters long'
: null;
}