maxLength static method

String? maxLength(
  1. String? value,
  2. int maxLength, {
  3. String? fieldName,
})

Validate maximum length

Implementation

static String? maxLength(String? value, int maxLength, {String? fieldName}) {
  if (value != null && value.length > maxLength) {
    return '${fieldName ?? 'This field'} must be at most $maxLength characters';
  }

  return null;
}