format static method

String format(
  1. String cep, {
  2. bool ponto = true,
  3. String onEmpty = "Não encontrado...",
})

Implementation

static String format(String cep, {bool ponto = true, String onEmpty = "Não encontrado..."}) {
  if(cep.isEmpty) return onEmpty;
  if(cep.length < 8) return cep;
  return ponto
      ? '${cep.substring(0, 2)}.${cep.substring(2, 5)}-${cep.substring(5, 8)}'
      : '${cep.substring(0, 2)}${cep.substring(2, 5)}-${cep.substring(5, 8)}';
}