I need help handling the null values for DateTime JSON parse. Since some of the data does not have createDate
, I have a problem showing the data
this is my code:
factory OfaModel.fromJson(Map<String, dynamic> json) => TestModel(
createdDate: DateTime.parse(json["CreatedDate"]),
recordtypeBm: json["recordtype_bm"],
amsCustodialHistoryBm: List<String>.from(json["AMSCustodialHistoryBM"].map((x) => x)),
subjectCode: json["SubjectCode"]
recordtypeBi: json["recordtype_bi"],
);
3
Answers
You just need to make a condition like that:
just check if it’s not or not,
You can use DateTime.tryParse()