Enhance Info model to handle optional JSON fields gracefully

This commit updates the Info class to provide default values for optional or missing fields in the JSON payload. This ensures that the model can be successfully instantiated even when some JSON fields are absent or set to null.
This commit is contained in:
hunteraraujo
2023-09-13 17:30:41 -07:00
parent 5e2e7a11c3
commit 3c35cab55e

View File

@@ -11,9 +11,9 @@ class Info {
factory Info.fromJson(Map<String, dynamic> json) {
return Info(
difficulty: json['difficulty'],
description: json['description'],
sideEffects: List<String>.from(json['side_effects']),
difficulty: json['difficulty'] ?? "",
description: json['description'] ?? "",
sideEffects: List<String>.from(json['side_effects'] ?? []),
);
}
}