I have a contact model that uses maps but the return is null thus causing aysnc suspension. I have tried tried setting these maps to return an empty list but to no avail do I manage to resolve the issue.
ContactModel{
//factory method constructor
emails: List<Email>.from(parsedJson['Emails'].map((x)=>Email.fromJson(x))),
tasks: List<Tasks>.from(parsedJson["Tasks"].map((x) => Tasks.fromJson(x))),
notes: List<Notes>.from(parsedJson["Notes"].map((x) => Notes.fromJson(x))),
}
The error returns as : No such method map called on null. Receiver null
I have tried to resolve the issue by writing it as such
ContactModel{
//factory method constructor
emails: List<Email>.from(parsedJson['Emails'].map((x)=>Email.fromJson(x))).toList() ?? [],
tasks: List<Tasks>.from(parsedJson["Tasks"].map((x) => Tasks.fromJson(x))).toList() ?? [],
notes: List<Notes>.from(parsedJson["Notes"].map((x) => Notes.fromJson(x))).toList() ?? [],
}