0
votes

Yo ,, during my experience of flutter i'll try to show on map marker saved into Json file..in this way i retrive only one of row

           Future<chiese> loadChiese() async {
            await wait(5);
             String jsonString = await _ChieseAsset();
              final jsonResponse = json.decode(jsonString);

           for ( var i=0; i < 5; i++ ){
            print(i);
           return new chiese.fromJson(jsonResponse[i]);
           }
          }

Unfortunally var i show only 0 value and don't scan into json retrive only first value why???

if i use ...

           Future<chiese> loadChiese() async {
           await wait(5);
           String jsonString = await _ChieseAsset();
           final jsonResponse = json.decode(jsonString);
           return new chiese.fromJson(jsonResponse);
             }

Reciving error ... [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: type 'List' is not a subtype of type 'Map'

Any idea??? Thanks

1

1 Answers

1
votes

Change this:

return new chiese.fromJson(jsonResponse);

Into this:

return new chiese.fromJson(jsonResponse[0]);