1
resposta

Erro de conversao da api

Boa noite estou com problema em buscar o cep usando o via cep na hora da conversao.

ERRO MOSTRADO I/flutter ( 9515): Request I/flutter ( 9515): url: https://viacep.com.br/ws/19013380/json/ I/flutter ( 9515): headers: {} I/flutter ( 9515): body: I/flutter ( 9515): Response I/flutter ( 9515): status code: 200 I/flutter ( 9515): headers: {connection: keep-alive, cache-control: max-age=3600,public, access-control-allow-origin: *, transfer-encoding: chunked, date: Sat, 28 Mar 2020 01:56:02 GMT, content-type: application/json; charset=utf-8, access-control-max-age: 86400, pragma: public, server: nginx/1.16.1, access-control-allow-headers: Content-Type, X-Request-With, X-Requested-By, access-control-allow-credentials: true, access-control-allow-methods: GET, OPTIONS, expires: Sat, 28 Mar 2020 02:56:02 GMT} I/flutter ( 9515): body: { I/flutter ( 9515): "cep": "19013-380", I/flutter ( 9515): "logradouro": "Avenida Quatorze de Setembro", I/flutter ( 9515): "complemento": "até 699/700", I/flutter ( 9515): "bairro": "Vila Industrial", I/flutter ( 9515): "localidade": "Presidente Prudente", I/flutter ( 9515): "uf": "SP", I/flutter ( 9515): "unidade": "", I/flutter ( 9515): "ibge": "3541406", I/flutter ( 9515): "gia": "5629" I/flutter ( 9515): } E/flutter ( 9515): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: NoSuchMethodError: Class '_InternalLinkedHashMap<String, dynamic>' has no instance method 'toList'.

CODIGO

RaisedButton( child: Text( "CADASTRAR", style: TextStyle(color: Colors.white,fontSize: 18), ), color: Colors.lightGreen, shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(8), side: BorderSide(color: Colors.lightGreen)), onPressed: () async{

                              final List<ResultCep> resultCep  =  await ResultCepWebClient().findCep(_cep.text);
                              print("LISTAAA : :::" + resultCep.toString());
                              setState(() {

                              });
                            },
                          )

classe utilizada Future<List> findCep(String cep) async { final Response response = await client.get(returnUrlCep(cep)).timeout(Duration(seconds: 5)); print("body ::::"+ response.body); final List decodedJson = jsonDecode(response.body).toList(); return decodedJson .map((dynamic json) => ResultCep.fromJson(json)) .toList(); }

1 resposta

Oi Felipe, tudo bem ?

Cara eu vi que sua dúvida é um pouco antiga, será que tu já resolveu ? Se sim pode compartilhar conosco ?