From a15f8712dda4265d44b7c383640610e048321075 Mon Sep 17 00:00:00 2001 From: monsieurtanuki Date: Thu, 14 Dec 2023 16:44:20 +0100 Subject: [PATCH] fix: 4627 - no more nutrients wiped out Impacted files: * `ordered_nutrients_cache.dart`: removed a bug I introduced in #4768. * `up_to_date_changes.dart`: now nutriments are safer when background tasks are running. --- packages/smooth_app/lib/data_models/up_to_date_changes.dart | 5 ++++- .../lib/pages/product/ordered_nutrients_cache.dart | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/smooth_app/lib/data_models/up_to_date_changes.dart b/packages/smooth_app/lib/data_models/up_to_date_changes.dart index d46cf4df2f7..050964bdd47 100644 --- a/packages/smooth_app/lib/data_models/up_to_date_changes.dart +++ b/packages/smooth_app/lib/data_models/up_to_date_changes.dart @@ -80,7 +80,10 @@ class UpToDateChanges { if (change.noNutritionData != null) { initial.noNutritionData = change.noNutritionData; } - if (change.nutriments != null) { + // cf. https://github.com/openfoodfacts/smooth-app/issues/4627 + // If we don't check if nutriments is empty, most of the time we overwrite + // potentially existing nutriments with an empty map. + if (change.nutriments != null && !change.nutriments!.isEmpty()) { initial.nutriments = change.nutriments; } if (change.servingSize != null) { diff --git a/packages/smooth_app/lib/pages/product/ordered_nutrients_cache.dart b/packages/smooth_app/lib/pages/product/ordered_nutrients_cache.dart index 26815d4989f..9bbdf121a0b 100644 --- a/packages/smooth_app/lib/pages/product/ordered_nutrients_cache.dart +++ b/packages/smooth_app/lib/pages/product/ordered_nutrients_cache.dart @@ -24,7 +24,7 @@ class OrderedNutrientsCache { cache._orderedNutrients = await cache._get(); if (cache._orderedNutrients == null) { if (context.mounted) { - await LoadingDialog.run( + cache._orderedNutrients = await LoadingDialog.run( context: context, future: cache._download(), );