Equals static method
Returns a validator that checks if a string equals to given string. It can be used in specific cases like password confirmation.
Arguments :
value
: The value to matcherrorMessage
: The error message to return if the string does not match the pattern.next
: A validator to run after this validator.
Usage :
TextFormField(
validator: Validators.Equals(value : 'value_to_match'),
),
Implementation
static String? Function(String? value)? Equals({
required String value,
String errorMessage = 'Value matches to the given value',
String? Function(String value)? next,
}) {
return (v) {
if (v == null || v.trim().isEmpty) {
return null;
}
if (v == value) {
return errorMessage;
}
if (next != null) {
return next(v);
}
return null;
};
}