-
-
Notifications
You must be signed in to change notification settings - Fork 302
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 5203 - "add receipt" and "add price tags", even offline or not …
…found (#5392) Impacted files: * `app_en.arb`: added 2 "add" and 4 "price product" labels * `app_fr.arb`: added 2 "add" and 4 "price product" labels * `edit_product_page.dart`: minor refactoring * `get_prices_model.dart`: minor refactoring * `price_amount_card.dart`: added the case of "no product yet" * `price_amount_model.dart`: added "no product yet" check * `price_meta_product.dart`: 2 more cases - "no product yet" and "not found product" * `price_product_list_tile.dart`: minor refactoring * `price_product_search_page.dart`: now we accept "not found" products and we don't force the server lookup * `prices_card.dart`: minor refactoring * `product_price_add_page.dart`: minor refactoring * `user_preferences_account.dart`: added "Add receipt" and "Add price tags"
- Loading branch information
1 parent
4b4f387
commit b9f83c4
Showing
12 changed files
with
174 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 70 additions & 14 deletions
84
packages/smooth_app/lib/pages/prices/price_meta_product.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,81 @@ | ||
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/widgets/images/smooth_image.dart'; | ||
import 'package:smooth_app/generic_lib/widgets/smooth_product_image.dart'; | ||
import 'package:smooth_app/helpers/product_cards_helper.dart'; | ||
|
||
/// Meta version of a product, coming from OFF or from Prices. | ||
class PriceMetaProduct { | ||
PriceMetaProduct.product(Product this.product) : priceProduct = null; | ||
PriceMetaProduct.priceProduct(PriceProduct this.priceProduct) | ||
: product = null; | ||
PriceMetaProduct.product(final Product product) | ||
: _product = product, | ||
_priceProduct = null, | ||
_barcode = null; | ||
PriceMetaProduct.priceProduct(final PriceProduct priceProduct) | ||
: _product = null, | ||
_priceProduct = priceProduct, | ||
_barcode = null; | ||
PriceMetaProduct.empty() | ||
: _product = null, | ||
_priceProduct = null, | ||
_barcode = null; | ||
PriceMetaProduct.unknown(final String barcode) | ||
: _product = null, | ||
_priceProduct = null, | ||
_barcode = barcode; | ||
|
||
final Product? product; | ||
final PriceProduct? priceProduct; | ||
final Product? _product; | ||
final PriceProduct? _priceProduct; | ||
final String? _barcode; | ||
|
||
String get barcode => | ||
product != null ? product!.barcode! : priceProduct!.code; | ||
// TODO(monsieurtanuki): refine this test | ||
bool get isValid => barcode.length >= 8; | ||
|
||
String getName(final AppLocalizations appLocalizations) => product != null | ||
? getProductNameAndBrands( | ||
product!, | ||
appLocalizations, | ||
) | ||
: priceProduct!.name ?? priceProduct!.code; | ||
String get barcode { | ||
if (_product != null) { | ||
return _product.barcode!; | ||
} | ||
if (_priceProduct != null) { | ||
return _priceProduct.code; | ||
} | ||
return _barcode ?? ''; | ||
} | ||
|
||
String? get imageUrl => product != null ? null : priceProduct!.imageURL; | ||
String getName(final AppLocalizations appLocalizations) { | ||
if (_product != null) { | ||
return getProductNameAndBrands( | ||
_product, | ||
appLocalizations, | ||
); | ||
} | ||
if (_priceProduct != null) { | ||
return _priceProduct.name ?? _priceProduct.code; | ||
} | ||
if (barcode.isEmpty) { | ||
return appLocalizations.prices_barcode_search_none_yet; | ||
} | ||
return appLocalizations.prices_barcode_search_not_found; | ||
} | ||
|
||
Widget getImageWidget(final double size) { | ||
if (_product != null) { | ||
return SmoothMainProductImage( | ||
product: _product, | ||
width: size, | ||
height: size, | ||
); | ||
} | ||
if (_priceProduct != null) { | ||
final String? imageURL = _priceProduct.imageURL; | ||
return SmoothImage( | ||
width: size, | ||
height: size, | ||
imageProvider: imageURL == null ? null : NetworkImage(imageURL), | ||
); | ||
} | ||
return SmoothImage( | ||
width: size, | ||
height: size, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.