diff --git a/packages/app/pubspec.lock b/packages/app/pubspec.lock index 57942405981..1a4568a3d64 100644 --- a/packages/app/pubspec.lock +++ b/packages/app/pubspec.lock @@ -541,27 +541,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "3.2.0" - image_cropper: - dependency: transitive - description: - name: image_cropper - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.3" - image_cropper_for_web: - dependency: transitive - description: - name: image_cropper_for_web - url: "https://pub.dartlang.org" - source: hosted - version: "0.0.4" - image_cropper_platform_interface: - dependency: transitive - description: - name: image_cropper_platform_interface - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.0" image_picker: dependency: transitive description: diff --git a/packages/smooth_app/lib/pages/product/add_new_product_page.dart b/packages/smooth_app/lib/pages/product/add_new_product_page.dart index 9ba4fce1945..97d2c1d9f8b 100644 --- a/packages/smooth_app/lib/pages/product/add_new_product_page.dart +++ b/packages/smooth_app/lib/pages/product/add_new_product_page.dart @@ -5,6 +5,8 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:openfoodfacts/model/Product.dart'; import 'package:openfoodfacts/model/ProductImage.dart'; import 'package:provider/provider.dart'; +import 'package:smooth_app/data_models/product_list.dart'; +import 'package:smooth_app/database/dao_product_list.dart'; import 'package:smooth_app/database/local_database.dart'; import 'package:smooth_app/generic_lib/buttons/smooth_large_button_with_icon.dart'; import 'package:smooth_app/generic_lib/design_constants.dart'; @@ -45,17 +47,24 @@ class _AddNewProductPageState extends State { late Product _product; late final Product _initialProduct; late final LocalDatabase _localDatabase; + late DaoProductList _daoProductList; + final ProductList _history = ProductList.history(); + + //likely broken: see https://github.com/openfoodfacts/smooth-app/issues/3445 bool get _nutritionFactsAdded => _product.nutriments != null; bool get _basicDetailsAdded => AddBasicDetailsPage.isProductBasicValid(_product); + bool _alreadyPushedtToHistory = false; + @override void initState() { super.initState(); _initialProduct = Product(barcode: widget.barcode); _localDatabase = context.read(); _localDatabase.upToDate.showInterest(widget.barcode); + _daoProductList = DaoProductList(_localDatabase); } @override @@ -67,10 +76,14 @@ class _AddNewProductPageState extends State { @override Widget build(BuildContext context) { final AppLocalizations appLocalizations = AppLocalizations.of(context); + context.watch(); final ThemeData themeData = Theme.of(context); _product = _localDatabase.upToDate.getLocalUpToDate(_initialProduct); final bool empty = _uploadedImages.isEmpty && _otherUploadedImages.isEmpty; + + _addToHistory(); + return SmoothScaffold( appBar: AppBar( title: Text(appLocalizations.new_product), @@ -106,6 +119,20 @@ class _AddNewProductPageState extends State { ); } + /// Adds the product to history if at least one of the fields is set. + Future _addToHistory() async { + if (_alreadyPushedtToHistory) { + return; + } + // TODO(open): Add _nutritionFactsAdded , see (https://github.com/openfoodfacts/smooth-app/issues/3445) + if (_basicDetailsAdded || + _uploadedImages.isNotEmpty || + _otherUploadedImages.isNotEmpty) { + await _daoProductList.push(_history, _product.barcode!); + _alreadyPushedtToHistory = true; + } + } + List _buildImageCaptureRows(BuildContext context) { final List rows = []; // First build rows for buttons to ask user to upload images.