i create flutter app which use the api from server when i get the JSON response from the server I parse the response and retrieve the sicke, serviceName, date, user, status and some more information about sicks, The problem is that some sicks in the JSON response don't have the doctororder key or medicalImagingOrder key and has diffrent key . When I try to get those JSON key values the program throws an error how i should handel this in the flutter?
this is how i create my object
class Datum {
Datum({
this.id,
this.sicke,
this.serviceName,
this.doctorOrder,
this.date,
this.user,
this.statusNumber,
this.status,
this.statusHistory,
this.insertDate,
this.statuses,
this.excessInvoice,
this.price,
this.shippingCosts,
this.vat,
this.netPrice,
this.totalPrice,
this.orderNumber,
this.v,
this.cancleReason,
this.medicalImagingOrder,
this.laboratoryOrder,
this.serviceProvider,
this.nurseOrder,
});
String id;
Sicke sicke;
String serviceName;
DoctorOrder doctorOrder;
DateTime date;
User user;
int statusNumber;
StatusEnum status;
List<StatusHistory> statusHistory;
DateTime insertDate;
List<StatusElement> statuses;
List<dynamic> excessInvoice;
int price;
int shippingCosts;
int vat;
int netPrice;
int totalPrice;
int orderNumber;
int v;
String cancleReason;
Order medicalImagingOrder;
LaboratoryOrder laboratoryOrder;
String serviceProvider;
Order nurseOrder;
factory Datum.fromJson(Map<String, dynamic> json) => Datum(
id: json["_id"],
sicke: json["sicke"] == null ? null : Sicke.fromJson(json["sicke"]),
serviceName: json["serviceName"],
doctorOrder: json["doctorOrder"] == null ? null : DoctorOrder.fromJson(json["doctorOrder"]),
date: DateTime.parse(json["date"]),
user: userValues.map[json["user"]],
statusNumber: json["statusNumber"],
status: statusEnumValues.map[json["status"]],
statusHistory: List<StatusHistory>.from(json["statusHistory"].map((x) => StatusHistory.fromJson(x))),
insertDate: DateTime.parse(json["insertDate"]),
statuses: List<StatusElement>.from(json["statuses"].map((x) => StatusElement.fromJson(x))),
excessInvoice: List<dynamic>.from(json["excessInvoice"].map((x) => x)),
price: json["price"],
shippingCosts: json["shippingCosts"],
vat: json["VAT"],
netPrice: json["netPrice"],
totalPrice: json["totalPrice"],
orderNumber: json["orderNumber"],
v: json["__v"],
cancleReason: json["cancleReason"] == null ? null : json["cancleReason"],
medicalImagingOrder: json["medicalImagingOrder"] == null ? null : Order.fromJson(json["medicalImagingOrder"]),
laboratoryOrder: json["laboratoryOrder"] == null ? null : LaboratoryOrder.fromJson(json["laboratoryOrder"]),
serviceProvider: json["serviceProvider"] == null ? null : json["serviceProvider"],
nurseOrder: json["nurseOrder"] == null ? null : Order.fromJson(json["nurseOrder"]),
);