How do I mount Listview of the result of an API call?

Asked

Viewed 29 times

0

I am making the call of an HTML and the return in JSON

var dadosJson = json.decode( response.body );

is the following string:

flutter: resposta dadosJson: {_embedded: {banks: [{number: 001, name: BCO DO BRASIL S.A.}, {number: 003, name: BCO DA AMAZONIA S.A.}, {number: 004, name: BCO DO NORDESTE DO BRASIL S.A.}, {number: 021, name: BCO BANESTES S.A.}, {number: 025, name: BCO ALFA S.A.}, {number: 033, name: BCO SANTANDER (BRASIL) S.A.}, {number: 036, name: BCO BBI S.A.}, {number: 037, name: BCO DO EST. DO PA S.A.}, {number: 041, name: BCO DO ESTADO DO RS S.A.}, {number: 047, name: BCO DO EST. DE SE S.A.}, {number: 062, name: HIPERCARD BM S.A.}, {number: 066, name: BCO MORGAN STANLEY S.A.}, {number: 069, name: BCO CREFISA S.A.}, {number: 070, name: BRB - BCO DE BRASILIA S.A.}, {number: 074, name: BCO. J.SAFRA S.A.},

But I’m not able to load the list only with the number and names of the banks. The list is null and gives execution error.

I tried so, but it does not load and gives error:

      List<Bancos> bancos = [];
      for( var listabanco in dadosJson ){
        print("nro banco: "+ listabanco["number"]);
      }

I created the Banks class

class Bancos{

  String _number;
  String _name;

  Bancos(this._number, this._name,);

  String get name => _name;
  set name(String value) {
    _name = value;
  }

  String get number => _number;
  set number(String value) {
    _number = value;
  }

}
  • Enter the code of your ListView, if you have not done anything here you have an example: https://api.flutter.dev/flutter/widgets/ListView-class.html

  • Thank you very much!!

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.