flutter merging two or more JSON data and using them as one in list view or future builder

Viewed 520

I've been working on a JSON file in my flutter app and I want to merge multiple JSON data in one Listview.builder in FutureBuilder. In my case I have an audio JSON file and text JSON file.

var data;

Future<void> getAll() async{

     // text JSON
    final url1 = "http://api.alquran.cloud/v1/quran/en.asad";
    Uri myUri1 = Uri.parse(url1);
    final response1 = await http.get(myUri1);

     //audio JSON
    final url2 = "http://api.alquran.cloud/v1/quran/ar.alafasy";
    Uri myUri2 = Uri.parse(url2);
    final response2 = await http.get(myUri2);
    
    /* here I want to combine 
    response = response1 + response2
    then add it to data as */

    if (response.statusCode == 200) {
        data = json.decode(response.body.toString());
    } else {
       throw Exception('Failed to load text');
    }
  }

so how can I combine these? and if I can add two how can I do it with more JSON data?

1 Answers

actually I found an answer for this. I just used it as follows.

data = json.decode(response1.body.toString());
      data.addAll(json.decode(response2.body.toString()));

I haven't tried it for more JSON data but it works fine for the two JSON files.

Related