fix: improve imageUrl handling in Recipe model to avoid null or empty values
This commit is contained in:
@@ -26,12 +26,16 @@ class Recipe {
|
||||
final dynamic rawImageUrl = json['imageUrl'];
|
||||
final dynamic rawServings = json['servings'];
|
||||
final rawIngredients = json['ingredients'] as List<dynamic>? ?? [];
|
||||
final normalizedImageUrl = rawImageUrl?.toString().trim();
|
||||
|
||||
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(),
|
||||
imageUrl:
|
||||
(normalizedImageUrl == null || normalizedImageUrl.isEmpty)
|
||||
? null
|
||||
: normalizedImageUrl,
|
||||
servings: rawServings == null
|
||||
? null
|
||||
: (rawServings is num
|
||||
|
||||
Reference in New Issue
Block a user