maxLength static method

String? Function(String?) maxLength(
  1. int length, [
  2. String? message
])

Maximum length

Implementation

static String? Function(String?) maxLength(int length, [String? message]) {
  return (value) {
    if (value == null || value.isEmpty) return null;
    if (value.length > length) {
      return message ?? 'Must be at most $length characters';
    }
    return null;
  };
}