0
votes

List data;

i want to show response but when i try to assign jasonResponse to data i get this error

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

so what should i do

how to assign array of object to data

Future<String> getJsonData() async{

    SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
    Map data = {'sale_id': sharedPreferences.getInt("token")};

    var jsonResponse;
    var response = await http.post(
      "http://",
      body: json.encode(data),
      headers: {
        "Content-Type": "application/json"

      },
    );

    if (response.statusCode == 200) {
      jsonResponse = json.decode(response.body);
      print('jsonRespnse');
      print(jsonResponse['developer_list']);
      if (jsonResponse != null) {
         setState(() {

          data = jsonResponse['developer_list'];

         });

1

1 Answers

1
votes

Your data is a type Map but you are assigning a type List.

Simply, add a key with your value, like below:

data['developer_list'] = jsonResponse['developer_list'];

Make sure to access that list by data['developer_list']