maxLength function

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

Creates a validator that fails when a string value exceeds n characters.

Returns message (or 'Must be at most $n characters.' by default) when invalid, and null when valid.

final bioField = BloomFormField(
  validators: [maxLength(280, 'Bio cannot exceed 280 characters.')],
);

Implementation

String? Function(String) maxLength(int n, [String? message]) =>
    (v) => v.length > n ? (message ?? 'Must be at most $n characters.') : null;