Skip to content

Commit

Permalink
feature/#886 - added 3 "add" buttons for scores (#889)
Browse files Browse the repository at this point in the history
Impacted files:
* `app_en.arb`: added 3 labels for the 3 new buttons
* `app_fr.arb`: added 3 labels for the 3 new buttons
* `knowledge_panels_builder.dart`: added 2 potential buttons
* `new_product_page.dart`: refactored
* `product_cards_helper.dart`: added method that create the button
* `summary_card.dart`: added 1 potential button
  • Loading branch information
monsieurtanuki authored Jan 7, 2022
1 parent 810ac43 commit 30332fa
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:openfoodfacts/model/KnowledgePanel.dart';
import 'package:openfoodfacts/model/KnowledgePanelElement.dart';
import 'package:openfoodfacts/model/KnowledgePanels.dart';
import 'package:openfoodfacts/openfoodfacts.dart';
import 'package:smooth_app/cards/product_cards/knowledge_panels/knowledge_panel_element_card.dart';
import 'package:smooth_app/helpers/product_cards_helper.dart';

class KnowledgePanelsBuilder {
const KnowledgePanelsBuilder();

List<Widget> build(KnowledgePanels knowledgePanels) {
List<Widget> build(
KnowledgePanels knowledgePanels, {
final Product? product,
final AppLocalizations? appLocalizations,
}) {
final List<Widget> rootPanelWidgets = <Widget>[];
if (knowledgePanels.panelIdToPanelMap['root'] == null) {
return rootPanelWidgets;
Expand All @@ -20,8 +27,9 @@ class KnowledgePanelsBuilder {
if (panelElement.elementType != KnowledgePanelElementType.PANEL) {
continue;
}
final KnowledgePanel rootPanel = knowledgePanels
.panelIdToPanelMap[panelElement.panelElement!.panelId]!;
final String panelId = panelElement.panelElement!.panelId;
final KnowledgePanel rootPanel =
knowledgePanels.panelIdToPanelMap[panelId]!;
// [knowledgePanelElementWidgets] are a set of widgets inside the root panel.
final List<Widget> knowledgePanelElementWidgets = <Widget>[];
for (final KnowledgePanelElement knowledgePanelElement
Expand All @@ -31,6 +39,27 @@ class KnowledgePanelsBuilder {
allPanels: knowledgePanels,
));
}
if (product != null && appLocalizations != null) {
if (panelId == 'health_card') {
if (product.statesTags
?.contains('en:nutrition-facts-to-be-completed') ??
false) {
knowledgePanelElementWidgets.add(
dummyAddButton(
appLocalizations.score_add_missing_nutrition_facts,
),
);
}
if (product.statesTags?.contains('en:ingredients-to-be-completed') ??
false) {
knowledgePanelElementWidgets.add(
dummyAddButton(
appLocalizations.score_add_missing_ingredients,
),
);
}
}
}
rootPanelWidgets.add(Column(children: knowledgePanelElementWidgets));
}
return rootPanelWidgets;
Expand Down
9 changes: 9 additions & 0 deletions packages/smooth_app/lib/helpers/product_cards_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,12 @@ List<Attribute> getPopulatedAttributes(
}
return result;
}

Widget dummyAddButton(final String label) => SizedBox(
width: double.infinity,
child: ElevatedButton.icon(
icon: const Icon(Icons.add),
label: Text(label),
onPressed: () {}, // TODO(monsieurtanuki): to be implemented
),
);
3 changes: 3 additions & 0 deletions packages/smooth_app/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,9 @@
"@packaging_information_photo": {},
"missing_product": "This product is missing",
"@missing_product": {},
"score_add_missing_ingredients": "Add missing ingredients",
"score_add_missing_nutrition_facts": "Add missing nutrition facts",
"score_add_missing_product_category": "Add missing product category",
"more_photos": "More interesting photos",
"@more_photos": {},
"no_product_found": "No product found",
Expand Down
3 changes: 3 additions & 0 deletions packages/smooth_app/lib/l10n/app_fr.arb
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,9 @@
"@packaging_information_photo": {},
"missing_product": "Ce produit est manquant",
"@missing_product": {},
"score_add_missing_ingredients": "Ajouter les ingrédients",
"score_add_missing_nutrition_facts": "Ajouter les données nutritionnelles",
"score_add_missing_product_category": "Ajouter une catégorie de produit",
"more_photos": "Plus de photos intéressantes",
"@more_photos": {},
"no_product_found": "Aucun produit trouvé",
Expand Down
7 changes: 5 additions & 2 deletions packages/smooth_app/lib/pages/product/new_product_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,11 @@ class _ProductPageState extends State<ProductPage> {
List<Widget> knowledgePanelWidgets = <Widget>[];
if (snapshot.hasData) {
// Render all KnowledgePanels
knowledgePanelWidgets =
const KnowledgePanelsBuilder().build(snapshot.data!);
knowledgePanelWidgets = const KnowledgePanelsBuilder().build(
snapshot.data!,
product: _product,
appLocalizations: AppLocalizations.of(context),
);
} else if (snapshot.hasError) {
// TODO(jasmeet): Retry the request.
// Do nothing for now.
Expand Down
6 changes: 6 additions & 0 deletions packages/smooth_app/lib/pages/product/summary_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,12 @@ class _SummaryCardState extends State<SummaryCard> {
cardEvaluation: getCardEvaluationFromAttribute(attribute),
),
attributesContainer,
if (widget._product.statesTags
?.contains('en:categories-to-be-completed') ??
false)
dummyAddButton(
AppLocalizations.of(context)!.score_add_missing_product_category,
),
],
);
}
Expand Down

0 comments on commit 30332fa

Please sign in to comment.