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
validatorontarget, recording problems inerrors. -
rejectIfEmpty(
Errors errors, String field, String errorCode, {List< Object?> args = const [], String? defaultMessage}) → void -
Records an
errorCodeerror onfieldwhen its value isnull, 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.