cpf method

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

use to validate cpf fields

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

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

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

Implementation

String? cpf(String? value, {String error = 'CPF inválido'}) {
  String numbers = CPFValidator.strip(value ?? "");
  if (numbers.length != 11 || !CPFValidator.isValid(value ?? "")) {
    return error;
  }
  return null;
}