diff --git a/packages/smooth_app/lib/helpers/analytics_helper.dart b/packages/smooth_app/lib/helpers/analytics_helper.dart index b8b3b994877..2a82e982114 100644 --- a/packages/smooth_app/lib/helpers/analytics_helper.dart +++ b/packages/smooth_app/lib/helpers/analytics_helper.dart @@ -65,6 +65,14 @@ enum AnalyticsEvent { tag: 'showed fast-track product edit card', category: AnalyticsCategory.productFastTrackEdit, ), + notShowFastTrackProductEditCardNutriscore( + tag: 'nutriscore not applicable - no fast-track product edit card', + category: AnalyticsCategory.productFastTrackEdit, + ), + notShowFastTrackProductEditCardEcoscore( + tag: 'ecoscore not applicable - no fast-track product edit card', + category: AnalyticsCategory.productFastTrackEdit, + ), categoriesFastTrackProductPage( tag: 'set categories on fast track product page', category: AnalyticsCategory.productFastTrackEdit, diff --git a/packages/smooth_app/lib/pages/product/product_incomplete_card.dart b/packages/smooth_app/lib/pages/product/product_incomplete_card.dart index e471c7055d4..2548c528594 100644 --- a/packages/smooth_app/lib/pages/product/product_incomplete_card.dart +++ b/packages/smooth_app/lib/pages/product/product_incomplete_card.dart @@ -2,6 +2,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:openfoodfacts/openfoodfacts.dart'; import 'package:smooth_app/generic_lib/design_constants.dart'; +import 'package:smooth_app/helpers/analytics_helper.dart'; import 'package:smooth_app/pages/product/add_new_product_page.dart'; import 'package:smooth_app/pages/product/product_field_editor.dart'; import 'package:smooth_app/pages/product/simple_input_page_helpers.dart'; @@ -20,6 +21,24 @@ class ProductIncompleteCard extends StatelessWidget { final bool isLoggedInMandatory; static bool isProductIncomplete(final Product product) { + bool checkScores = true; + if (_isNutriscoreNotApplicable(product)) { + AnalyticsHelper.trackEvent( + AnalyticsEvent.notShowFastTrackProductEditCardNutriscore, + barcode: product.barcode, + ); + checkScores = false; + } + if (_isEcoscoreNotApplicable(product)) { + AnalyticsHelper.trackEvent( + AnalyticsEvent.notShowFastTrackProductEditCardEcoscore, + barcode: product.barcode, + ); + checkScores = false; + } + if (!checkScores) { + return false; + } final List editors = [ ProductFieldSimpleEditor(SimpleInputPageCategoryHelper()), ProductFieldNutritionEditor(), @@ -34,6 +53,34 @@ class ProductIncompleteCard extends StatelessWidget { return false; } + static bool _isNutriscoreNotApplicable(final Product product) => + _isScoreNotApplicable(product, 'nutriscore'); + + static bool _isEcoscoreNotApplicable(final Product product) => + _isScoreNotApplicable(product, 'ecoscore'); + + static bool _isScoreNotApplicable(final Product product, final String tag) => + _getAttribute(product, tag)?.iconUrl == + 'https://static.openfoodfacts.org/images/attributes/$tag-not-applicable.svg'; + + // TODO(monsieurtanuki): move to off-dart (or find it there) + static Attribute? _getAttribute(final Product product, final String id) { + if (product.attributeGroups == null) { + return null; + } + for (final AttributeGroup attributeGroup in product.attributeGroups!) { + if (attributeGroup.attributes == null) { + continue; + } + for (final Attribute attribute in attributeGroup.attributes!) { + if (attribute.id == id) { + return attribute; + } + } + } + return null; + } + @override Widget build(BuildContext context) { final AppLocalizations appLocalizations = AppLocalizations.of(context);