According to my previous question I'm already solve the null safety problem, but here i got the new problem about initializer on my model, here's the short code of my model looks like and I got the error from here:
LeaveListResponse({
this.total,
this.result,
});
LeaveListResponse.fromJson(Map<String, dynamic> json) {
total = json['total'] as int?;
result = (json['result'] as List?)
?.map((dynamic e) =>
LeaveListResponse.fromJson(e as Map<String, dynamic>))
.toList();
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> json = <String, dynamic>{};
json['total'] = total;
json['result'] = result?.map((e) => e.toJson()).toList();
return json;
}
}
class LeaveListResult {
int? paidLeaveId;
String? paidLeaveUuid;
String? paidLeaveEmployeeUuid;
String? paidLeaveEmployeeNip;
String? paidLeaveEmployeeFullName;
String? paidLeaveTypeUuid;
String? paidLeaveTypeName;
String? paidLeaveTypeDetailUuid;
String? hirarki;
int? levels;
int? jumlahHari;
I'm calling the model inside:
LeaveListModel responses =
snapshot.data!.data as LeaveListModel;
return Text(responses.response?.paidLeaveTypeName?? "");
so after I put the null safety inside the Text()
it start to showing the error on my model, how to initialize paidLeaveTypeName
?