Я пытаюсь преобразовать свой ответ json в список, но получаю сообщение об ошибке ниже.Json извлекается из карты, но необходимо преобразовать карту в список и отобразить в виде списка.
"_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'List<dynamic>'"
Ответ Json
{"78":{"id":118,"first_name":"test","last_name":null,"email":"jignesh.test@gmail.com","phone":"","city":"null","state":"null","countrie_id":1,"location":"null","lat":"37.421998333333335","lng":"-122.08400000000002","image":"","role_id":3,"client_id":3,"coordinator_id":1,"sst_id":2,"created_at":"2018-10-08 10:59:18","updated_at":"2018-10-08 10:59:18","deleted_at":null,"status":0},
"79":{"id":119,"first_name":"Rahul test","last_name":null,"email":"rahul.test@gmail.com","phone":"","city":"null","state":"null","countrie_id":1,"location":"null","lat":"19.2284","lng":"72.85813","image":"","role_id":3,"client_id":3,"coordinator_id":1,"sst_id":2,"created_at":"2018-10-08 11:19:14","updated_at":"2018-10-08 11:19:14","deleted_at":null,"status":0},
"80":{"id":120,"first_name":"Customer Name","last_name":null,"email":"jjkkk@gmail.com","phone":"","city":"Mumbai","state":"Maharastra","countrie_id":1,"location":"virar","lat":"123","lng":"456","image":"images\/customer_image\/0hUSFUSqYAQTt57bVnnHjuQUOACECWzBOfJLWWa6.png","role_id":3,"client_id":1,"coordinator_id":1,"sst_id":2,"created_at":"2018-10-09 12:24:08","updated_at":"2018-10-09 14:03:07","deleted_at":null,"status":0},"status":"success","message":"List Fetched Successfully."}
Ниже приведен мой метод Future для вызова метода post api.
Future<PosModelData> posList(){
print('pos list api called');
return networkUtil.post("http://192.168.0.46/api/v1/poslist",body:{
"sstId":"2"
}).then((response){
if(response["status"]=="success"){
print("List fetched");
posLists=((response) as List).map((data)=>new PosModelData.fromJson(data)).toList();
// print(response.toString());
// print(posLists);
}
});
}
PosModel.dart
class PosModelData {
final String first_name;
final String last_name;
final String email;
PosModelData({this.first_name, this.last_name, this.email});
factory PosModelData.fromJson(Map json) {
return new PosModelData(
first_name: json['first_name'],
last_name: json['last_name'],
email: json['email'],
);
}
}
NetworkUtil.dart
Future<dynamic> post(String url, {Map header, body, encoding}) {
return http
.post(url, body: body, headers: header, encoding: encoding)
.then((http.Response response) {
final String resBody = response.body;
return jsonDecoder.convert(resBody);
});
}