Error: List<dynamic> is not a subtype of type Map<String, dynamic>

API returns JSON array not json object so that is List not Map.

i.e. User json is first element of Json Array.

So to get first element use first index. Inside fetch Info update

return Users.fromJson(jsonresponse[0]);


var streetsFromJson = parsedJson['streets'];
List<String> streetsList = new List<String>.from(streetsFromJson);

Thnx for https://medium.com/flutter-community/parsing-complex-json-in-flutter-747c46655f51


Check out this Answer

 Future<List<ProductList>> getProductList() async {
  print("comes");
  String productURl= mainURL+'api/store/product-with-category/';

  final response = await http.get(productURl,headers:{"Content-Type": 
 "application/json"});
  List jsonResponse = json.decode(response.body);
  return jsonResponse.map((job) => new ProductList.fromJson(job)).toList();
  
}

Fetch function

    FutureBuilder<List<ProductList>>(
    future: getProductList(),
    builder: (context, snapshot) {
      print("snapshot");
      print(snapshot.data);
      if (snapshot.hasData) {
        return Padding(
          padding: const EdgeInsets.all(8.0),
          child: GridView.builder(
          itemCount: snapshot.data.length,
            gridDelegate:SliverGridDelegateWithFixedCrossAxisCount( crossAxisCount: 2,),
            itemBuilder:  (BuildContext context, int i){
              return Card(
                child: Container(
                  decoration: BoxDecoration(
                      border: Border.all(width: 0.5,color: Colors.grey)
                  ),
                  child: Padding(
                    padding: const EdgeInsets.all(8.0),
                    child: Column(
                      children: <Widget>[
                         text18(snapshot.data[i].title, Colors.black, FontWeight.bold)
                      ],
                    ),
                  ),
                ),
              );
            }
        )
        );
      } else if (snapshot.hasError) {
        return Text("${snapshot.error}");
      }


      // By default, show a loading spinner.
      return CircularProgressIndicator();
    },
  ),

just change URL and create model class

Tags:

Json

Flutter