maxLength method Null safety

Validator maxLength(
  1. int length,
  2. {bool trim = false,
  3. String message = "Validator.maxLength"}
)

Returns a Validator that accepts a value that is shorter or of equal length to length.

If the value is null, its length is treated as zero.

If trim is true leading and trailing spaces will be ignored.

Implementation

Validator maxLength(
  int length, {
  bool trim = false,
  String message = "Validator.maxLength",
}) {
  return add(
    (value) {
      var v = trim ? (value ?? "").trim() : (value ?? "");
      return v.length > length ? message : null;
    },
  );
}