ValidationUtils class abstract final

Static helpers for writing and running a Validator.

The two reject... helpers save the most common check of a hand-written validator, a required field. invokeValidator runs a validator with the checks a caller would otherwise repeat.

// A blank name is rejected with the code `required`.
final errors = MapBindingResult({'name': ' '}, 'form');
ValidationUtils.rejectIfEmptyOrWhitespace(errors, 'name', 'required');
errors.fieldError('name')!.codes.first; // 'required.form.name'

Spring (Java):

Errors errors = new MapBindingResult(Map.of("name", " "), "form");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "required");
errors.getFieldError("name").getCode(); // "required"

Properties

hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Methods

invokeValidator(Validator validator, Object target, Errors errors, {List<Type> groups = const []}) → void
Runs validator on target, recording problems in errors.
rejectIfEmpty(Errors errors, String field, String errorCode, {List<Object?> args = const [], String? defaultMessage}) → void
Records an errorCode error on field when its value is null, an empty string, or an empty list, set or map.
rejectIfEmptyOrWhitespace(Errors errors, String field, String errorCode, {List<Object?> args = const [], String? defaultMessage}) → void
Like rejectIfEmpty, but a string of only whitespace is rejected too.