validate method
override
Validates the current instance and returns a list of error messages if the instance is invalid.
Returns an empty list if the instance is valid.
Example usage:
class MyValidator implements Validator {
@override
List<String> validate() {
List<String> errors = [];
// Perform validation logic here
return errors;
}
}
Implementation
@override
List<String> validate() {
return [
if (nome.isBlank) "O nome é obrigatório",
if (cpfCnpj.isNotBlank)
if (Brasil.validarCPFouCNPJ(cpfCnpj) == false) "O CPF ou CNPJ inválido",
if (cnh.isNotBlank)
if (Brasil.validarCNH(cnh) == false) "A CNH é inválida",
if (pis.isNotBlank)
if (Brasil.validarPIS(pis) == false) "O PIS é inválido",
for (var email in emails)
if (!email.isEmail) "O email $email é inválido",
for (var telefone in telefones) ...[
if (telefone.numero.isBlank) "O telefone é obrigatório",
],
for (var endereco in enderecos) ...[
if (endereco.logradouro.isBlank) "O logradouro é obrigatório",
if (endereco.cidade == null) "A cidade é obrigatória",
if (endereco.estado == null) "O estado é obrigatório",
]
];
}