annotate method
Annotates value
with this validator returning an AnnotationResult.
This mechanic is used to provide more information about the validation
error.
Implementation
@override
AnnotationResult annotate(bool cached, value, DogEngine engine) {
final isValid = validate(cached, value, engine);
if (isValid) return AnnotationResult.empty();
if (max == null) {
return AnnotationResult(messages: [
AnnotationMessage(id: messageMinId, message: "Must be at least %min% characters long")
]).withVariables({
"min": min.toString(),
});
} else if (min == null) {
return AnnotationResult(messages: [
AnnotationMessage(id: messageMaxId, message: "Must be at most %max% characters long")
]).withVariables({
"max": max.toString(),
});
}
return AnnotationResult(messages: [
AnnotationMessage(id: messageId, message: "Must be between %min% and %max% characters long")
]).withVariables({
"min": min.toString(),
"max": max.toString(),
});
}