buscaTodosEstados method
Busca todos os estados brasileiros
Implementation
Future<List<Estado>> buscaTodosEstados() async {
try {
final uri = Uri.parse(urlBase);
final response = await http.get(uri);
if (response.statusCode == 200) {
final decodedResponse = jsonDecode(response.body) as List;
return List.generate(
decodedResponse.length,
(i) => Estado.fromJson(
decodedResponse[i],
),
);
} else {
throw FalhaBuscaEstadosException('Erro ao buscar estados no servidor');
}
} on Exception {
throw FalhaBuscaEstadosException('Erro ao buscar estados');
}
}