Refactor SkillNodeData model for robust JSON deserialization

This commit updates the SkillNodeData class to handle optional or missing JSON fields more robustly. Now, the model provides default values for each field, ensuring that the object can be instantiated successfully even if some JSON fields are missing or set to null.
This commit is contained in:
hunteraraujo
2023-09-13 17:31:00 -07:00
parent 3c35cab55e
commit 774ccc4ed2

View File

@@ -22,13 +22,13 @@ class SkillNodeData {
factory SkillNodeData.fromJson(Map<String, dynamic> json) {
return SkillNodeData(
name: json['name'],
category: List<String>.from(json['category']),
task: json['task'],
dependencies: List<String>.from(json['dependencies']),
cutoff: json['cutoff'],
ground: Ground.fromJson(json['ground']),
info: Info.fromJson(json['info']),
name: json['name'] ?? "",
category: List<String>.from(json['category'] ?? []),
task: json['task'] ?? "",
dependencies: List<String>.from(json['dependencies'] ?? []),
cutoff: json['cutoff'] ?? 0,
ground: Ground.fromJson(json['ground'] ?? {}),
info: Info.fromJson(json['info'] ?? {}),
);
}
}