0

I am parsing a complex json data into my flutter app. I have attached my code and my json data below.I am getting my data into the "newData".But getting the below error. Error: "Unhandled Exception: type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'Iterable". Wanted to show it in the Listview.Help is highly appereciated

JSON Data

  {

"Status":200,

"Message":"Success",

"data":{

    "TotalRecords":10,

    "Records":[

                 {

                 "Id":1,

                 "title":"Smile Crowdfunding",

                 "shortDescription":"This foundation will bring smile on there faces",

                 "collectedValue":500,

                 "totalValue":5000,

                 "startDate":"05/05/2018",

                 "endDate":"10/06/2018",

                 "mainImageURL":"http://iphonedeveloperguide.com/oneinr/project1.jpg"

                 },

                 {

                 "Id":2,

                 "title":"Animal Funding",

                 "shortDescription":"This foundation will help animals",

                 "collectedValue":200,

                 "totalValue":10000,

                "startDate":"10/05/2018",

                "endDate":"11/06/2018",

                 "mainImageURL":"http://iphonedeveloperguide.com/oneinr/project2.jpg"

                 }
            ]

    }

}

Code

 class _ShowListState extends State<ShowList> {
  var loading = false;
  List<Record> dataModel = [];
  Future<Null> getData() async{    
    final responseData = await http.get("https://xxxxxxx.json");    
    if(responseData.statusCode == 200){
      Map<String, dynamic> map = jsonDecode(responseData.body);
      LinkedHashMap<String,dynamic> data = map["data"];
      List<dynamic> newData = data["Records"];        
      print("newData: $newData");
      setState(() {
        for(Map i in newData[1]){
          dataModel.add(Record.fromJson(i));
          print("newData: $data");
        }
        loading = false;
      });
    }
  }
  void initState() {
    // TODO: implement initState
    super.initState();
    getData();
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Machine Test'),
      ),
      body: Container(
        child: loading? Center(
          child: CircularProgressIndicator()):
        ListView.builder(
            itemCount: dataModel.length,
            itemBuilder: (context,i){
              final nDataList = dataModel[i];
              return Container(
                child: Text(nDataList.title),
              );
            } ),
        ),
      );
  }
}
1
  • 2
    Remove square brackets :Map i in newData[1] Commented Sep 2, 2020 at 6:51

1 Answer 1

1

As Eldar said in the comment:

for(Map i in newData[1]){

needs to be

for(Map i in newData){
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.