Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added nutrition input to product addition flow #1751

Merged
merged 3 commits into from
May 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -415,8 +415,11 @@
},
"ingredients_photo_uploaded": "Ingredients photo uploaded",
"@ingredients_photo_uploaded": {},
"nutrition_cache_loading_error": "Unable to load nutrients from cache",
"nutritional_facts_photo_button_label": "Nutrition facts photo",
"@nutritional_facts_photo_button_label": {},
"nutritional_facts_input_button_label": "Input nutrition facts",
"nutritional_facts_added": "Nutrition facts added",
"confirm_nutritional_facts_photo_button_label": "Confirm nutrition facts photo",
"@confirm_nutritional_facts_photo_button_label": {
"description": "Button clicking on which confirms the picture of nutritional facts that user just took."
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 @@ -415,7 +415,10 @@
},
"ingredients_photo_uploaded": "Photo des ingrédients téléchargée",
"@ingredients_photo_uploaded": {},
"nutrition_cache_loading_error": "Impossible de charger les nutriments depuis le cache",
"nutritional_facts_photo_button_label": "Photo des informations nutritionnelles",
"nutritional_facts_input_button_label": "Insérer les informations nutritionnelles",
"nutritional_facts_added": "Informations nutritionnelles ajoutées",
"@nutritional_facts_photo_button_label": {},
"confirm_nutritional_facts_photo_button_label": "Confirmer la photo de la valeur nutritive",
"@confirm_nutritional_facts_photo_button_label": {
Expand Down
68 changes: 68 additions & 0 deletions packages/smooth_app/lib/pages/product/add_new_product_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:openfoodfacts/model/Product.dart';
import 'package:openfoodfacts/model/ProductImage.dart';
import 'package:smooth_app/generic_lib/buttons/smooth_action_button.dart';
import 'package:smooth_app/generic_lib/buttons/smooth_large_button_with_icon.dart';
import 'package:smooth_app/generic_lib/design_constants.dart';
import 'package:smooth_app/pages/image_crop_page.dart';
import 'package:smooth_app/pages/product/confirm_and_upload_picture.dart';
import 'package:smooth_app/pages/product/nutrition_page_loaded.dart';
import 'package:smooth_app/pages/product/ordered_nutrients_cache.dart';

const EdgeInsets _ROW_PADDING_TOP = EdgeInsets.only(top: VERY_LARGE_SPACE);

Expand Down Expand Up @@ -35,6 +38,7 @@ class _AddNewProductPageState extends State<AddNewProductPage> {
final Map<ImageField, List<File>> _uploadedImages =
<ImageField, List<File>>{};

bool _nutritionFactsAdded = false;
bool _isProductLoaded = false;

@override
Expand Down Expand Up @@ -69,6 +73,7 @@ class _AddNewProductPageState extends State<AddNewProductPage> {
.apply(color: themeData.colorScheme.onSurface),
),
..._buildImageCaptureRows(context),
_buildNutritionInputButton(),
],
),
),
Expand Down Expand Up @@ -206,4 +211,67 @@ class _AddNewProductPageState extends State<AddNewProductPage> {
bool _isImageUploadedForType(ImageField imageType) {
return (_uploadedImages[imageType] ?? <File>[]).isNotEmpty;
}

Widget _buildNutritionInputButton() {
if (_nutritionFactsAdded) {
return Padding(
padding: _ROW_PADDING_TOP,
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
const SizedBox(
width: 50.0,
child: Icon(
Icons.check,
color: Colors.greenAccent,
),
),
Expanded(
child: Center(
child: Text(
AppLocalizations.of(context)!.nutritional_facts_added,
style: Theme.of(context).textTheme.bodyText1),
),
),
],
));
}

return Padding(
padding: _ROW_PADDING_TOP,
child: SmoothLargeButtonWithIcon(
text:
AppLocalizations.of(context)!.nutritional_facts_input_button_label,
icon: Icons.edit,
onPressed: () async {
final OrderedNutrientsCache? cache =
await OrderedNutrientsCache.getCache(context);
if (cache == null) {
final SnackBar snackBar = SnackBar(
content: Text(
AppLocalizations.of(context)!.nutrition_cache_loading_error),
);
ScaffoldMessenger.of(context).showSnackBar(snackBar);
return;
}

final bool result = await Navigator.push<bool>(
context,
MaterialPageRoute<bool>(
builder: (BuildContext context) => NutritionPageLoaded(
Product(barcode: widget.barcode),
cache.orderedNutrients,
),
),
) ??
false;

setState(() {
_nutritionFactsAdded = result;
});
},
),
);
}
}