obterTelefone method

String obterTelefone (
  1. String telefone,
  2. {bool ddd: true}
)

Implementation

static String obterTelefone(String telefone, {bool ddd = true}) {
  if (ddd) {
    assert(telefone.length == 11,
        'Telefone com tamanho inválido. Deve conter 11 caracteres');
    return '(' +
        telefone.substring(0, 2) +
        ') ' +
        telefone.substring(2, 7) +
        '-' +
        telefone.substring(7, 11);
  }
  assert(telefone.length == 9,
      'Telefone com tamanho inválido. Deve conter 9 caracteres');
  return telefone.substring(0, 5) + '-' + telefone.substring(5, 9);
}