Equals static method

String? Function(String? value)? Equals({
  1. required String value,
  2. String errorMessage = 'Value matches to the given value',
  3. String? next(
    1. String value
    )?,
})

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 match
  • errorMessage : 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;
  };
}