validate method
Executes each of the validators, in order. This will fail-fast where it will stop walking the list as soon as any validator returns an error.
A return value of null
means all validators passed. A non-null response
is the error message that can be displayed to the user.
The context is used to attempt to find a valid Translator
on the
widget tree. This allows applications the ability to provide their own
translated strings for error messages.
See also:
Implementation
String? validate({
required String label,
required String? value,
}) {
String? error;
for (var v in validators) {
error = v.validate(
label: label,
value: value,
);
if (error?.isNotEmpty == true) {
break;
}
}
// Normalize empty strings to `null` for API consistency.
return error?.isEmpty == true ? null : error;
}