class Recipe { final int id; final String title; final String? description; final String? imageUrl; final int? servings; const Recipe({ required this.id, required this.title, this.description, this.imageUrl, this.servings, }); factory Recipe.fromJson(Map json) { final dynamic rawId = json['id']; final dynamic rawTitle = json['title'] ?? json['name']; final dynamic rawDescription = json['description']; final dynamic rawImageUrl = json['imageUrl']; final dynamic rawServings = json['servings']; return Recipe( id: rawId is num ? rawId.toInt() : int.parse(rawId.toString()), title: (rawTitle ?? '').toString(), description: rawDescription == null ? null : rawDescription.toString(), imageUrl: rawImageUrl == null ? null : rawImageUrl.toString(), servings: rawServings == null ? null : (rawServings is num ? rawServings.toInt() : int.tryParse(rawServings.toString())), ); } }