compare method
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;
}