cpfOrCnpj method

String? cpfOrCnpj(
  1. String? value, {
  2. String errorCPF = 'CPF inválido',
  3. String errorCNPJ = 'CNPJ inválido',
})

use to validate cpfOrCnpj fields

TextFormField(
  autovalidateMode: AutovalidateMode.onUserInteraction,
  validator: (value) => Mask.validations.cpfOrCnpj(
    value,
    error: 'your message error', // optional field
  ),
),

------------ or ------------

TextFormField(
  autovalidateMode: AutovalidateMode.onUserInteraction,
  validator: Mask.validations.cpfOrCnpj,
),

Implementation

String? cpfOrCnpj(
  String? value, {
  String errorCPF = 'CPF inválido',
  String errorCNPJ = 'CNPJ inválido',
}) {
  String? response = cpf(value, error: errorCPF);
  if (response != null) response = cnpj(value, error: errorCNPJ);
  return response;
}