Update Ground model to handle optional JSON fields

This commit modifies the Ground class to make it more robust against optional or missing fields in the incoming JSON data. Default values have been added to ensure that the model can be instantiated even if some JSON fields are missing or set to null.
This commit is contained in:
hunteraraujo
2023-09-13 17:29:05 -07:00
parent 63b235e7ce
commit 5e2e7a11c3

View File

@@ -15,11 +15,11 @@ class Ground {
factory Ground.fromJson(Map<String, dynamic> json) {
return Ground(
answer: json['answer'],
shouldContain: List<String>.from(json['should_contain']),
shouldNotContain: List<String>.from(json['should_not_contain']),
files: List<String>.from(json['files']),
eval: json['eval'],
answer: json['answer'] ?? "",
shouldContain: List<String>.from(json['should_contain'] ?? []),
shouldNotContain: List<String>.from(json['should_not_contain'] ?? []),
files: List<String>.from(json['files'] ?? []),
eval: json['eval'] ?? {},
);
}
}