cnpj method

String? cnpj(
  1. String? value, {
  2. String error = 'CNPJ inválido',
})

use to validate cnpj fields

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

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

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

Implementation

String? cnpj(String? value, {String error = 'CNPJ inválido'}) {
  String numbers = CNPJValidator.strip(value ?? "");
  if (numbers.length != 14 || !CNPJValidator.isValid(value ?? "")) {
    return error;
  }
  return null;
}