0

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 Answer 1

1

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']

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.