I am trying to get the JSON response from the server and output it to the Dart object.
In this class, I get data from the server:
class GetAllServicePostMethod extends ChangeNotifier {
List<AllServices> _getService;
List<AllServices> get allData => _getService;
set allData(List<AllServices> val) {
_getService = val;
notifyListeners();
}
Future<List<AllServices>> getInitService() async {
try {
var url = "url";
Map<String, String> headers = {
"auth-token": await SaveData.getDataAuthorization('Success')
};
var response = await http.get(url, headers: headers);
Map<String, dynamic> map = jsonDecode(response.body);
List<dynamic> res = map["data"];
List<AllServices> data = [];
for (var i = 1; i == 1 ; i++) {
print(allServicesFromJson(res[i]).runtimeType);
var initData = allServicesFromJson(res[i]);
data.add(initData);
}
allData = data;
return allData;
} catch (e) {
print(e);
}
}
and when i want to convert this jeson to the dart objec i have error : type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'String'
my postman output from server is like
Future<List<AllServices>> getInitService() async {
try {
var url = "http://185.73.112.57/users/services";
Map<String, String> headers = {
"auth-token": await SaveData.getDataAuthorization('Success')
};
var response = await http.get(url, headers: headers);
Map<String, dynamic> map = jsonDecode(response.body);
List<dynamic> res = map["data"];
List<AllServices> data = [];
for (var i = 1; i == 1 ; i++) {
print(allServicesFromJson(res[i]).runtimeType);
var initData = allServicesFromJson(res[i]);
data.add(initData);
}
allData = data;
return allData;
} catch (e) {
print(e);
}
} }
and my response is a json object like :
"data": [
{
"_id": "5fb8afeb10638586f271ee19",
"serviceName": "a",
"ambulanceInfo": {
"_id": "5fb8afeb10638586f271ee1a",
"services": [
{
"_id": "5fb8afeb10638586f271ee1b",
"serviceName": "code",
"status": true
},
{
"_id": "5fb8afeb10638586f271ee1c",
"serviceName": "withoutcode",
"status": true
}
],
"percent": 30
},
"sendSMS": true,
"sendEmail": true,
"status": true,
"__v": 0
},
{
"_id": "5fb8b03210638586f271ee24",
"serviceName": "b",
"laboratoryInfo": {
"_id": "5fb8b03210638586f271ee25",
"services": [
{
"_id": "5fb8b03210638586f271ee26",
"serviceName": " test",
"status": true
}
],
"percent": 30
},
"sendSMS": true,
"sendEmail": true,
"status": true,
"__v": 0
},
can any one help me to convert this?