maxLength static method

String? Function(String?) maxLength(
  1. int n, {
  2. String? message,
})

Returns a validator that enforces maximum length.

Implementation

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