fetchViaCepService function
Implementation
Future<Cep> fetchViaCepService(String cepWithLeftPad) async {
final url = Uri.parse('https://viacep.com.br/ws/$cepWithLeftPad/json/');
Cep resposta = const Cep();
final response = await http.get(
url,
headers: {
'content-type': 'application/json;charset=utf-8',
},
);
try {
final analyze = analyzeAndParseResponse(response);
if (analyze != null) resposta = extractCepValuesFromResponse(analyze);
} catch (e) {
throwApplicationError(e);
}
return resposta;
}