How to call nested json data using API in flutter?

You should Try below code your problem has been solved ->

Declare your API Call funtion

Future<List<dynamic>> getInfoData() async {
    String url="https://fillmmaka.com/gigocleanapi/cleanintypes.php";
    var response = await http.get(Uri.parse(url), headers: {
      'Content-Type': 'application/json',
      'Accept': 'application/json',
    });
    return json.decode(response.body)['Info'];
  }

Declare your Widget

Center(
    child: FutureBuilder<List<dynamic>>(
      future: getInfoData(),
      builder: (context, snapshot) {
        if (snapshot.hasData) {
          return Padding(
            padding: const EdgeInsets.all(8.0),
            child: ListView.builder(
              itemCount: snapshot.data.length,
              itemBuilder: (context, index) {
                var id = snapshot.data[index]['c_type_id'];
                var type = snapshot.data[index]['cleaning type'];

                return Card(
                  shape: RoundedRectangleBorder(
                    side: BorderSide(
                      color: Colors.green.shade300,
                    ),
                    borderRadius: BorderRadius.circular(15.0),
                  ),
                  child: ListTile(
                    leading: Text(id),
                    title: Text(type),
                  ),
                );
              },
            ),
          );
        }
        return CircularProgressIndicator();
      },
    ),
  ),

Your Screen look like this -> enter image description here

Leave a Comment