fix: improve imageUrl handling in Recipe model to avoid null or empty values

This commit is contained in:
Nils-Johan Gynther
2026-04-22 10:31:57 +02:00
parent c163821bad
commit 33eb5fbdb2
2 changed files with 10 additions and 1 deletions
@@ -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