compare method

String? compare(
  1. String? value, {
  2. String compareTo = '',
  3. String error = 'Compo inválido',
})

compare two fields such as password and password confirmation

TextFormField(
  autovalidateMode: AutovalidateMode.onUserInteraction,
  validator: (value) => Mask.validations.compare(
    value,
    compareTo: myTextEditingController.text,
    error: 'invalid confirmation' //optional field
  ),
),

Implementation

String? compare(
  String? value, {
  String compareTo = '',
  String error = 'Compo inválido',
}) {
  if ((value?.trim().isEmpty ?? true) || value != compareTo) return error;
  return null;
}