forked from openfoodfacts/smooth-app
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 5204 - preliminary step for multi-product price addition (openf…
…oodfacts#5367) * feat: 5204 - preliminary conceptual step New files: * `price_amount_model.dart`: Model for the price of a single product. * `price_meta_product.dart`: Meta version of a product, coming from OFF or from Prices. * `price_product_search_page.dart`: Product Search Page, for Prices. * `price_product_list_tile.dart`: Displays a meta product with an action button, as a ListTile. Impacted files: * `app_en.arb`: added 2 labels for the new "price product search" page * `app_fr.arb`: added 2 labels for the new "price product search" page * `edit_product_page.dart`: minor refactoring * `get_prices_model.dart`: minor refactoring * `price_amount_card.dart`: minor refactoring * `price_amount_field.dart`: minor refactoring * `price_count_widget.dart`: minor refactoring * `price_model.dart`: moved product amount code to new class `PriceAmountModel` * `price_product_widget.dart`: unrelated UI refactoring * `prices_card.dart`: minor refactoring * `product_price_add_page.dart`: minor refactoring * No "edit" button for product
- Loading branch information
1 parent
f5973da
commit 7bf53e8
Showing
15 changed files
with
499 additions
and
243 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
48 changes: 48 additions & 0 deletions
48
packages/smooth_app/lib/pages/prices/price_amount_model.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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_gen/gen_l10n/app_localizations.dart'; | ||
import 'package:smooth_app/pages/prices/price_meta_product.dart'; | ||
|
||
/// Model for the price of a single product. | ||
class PriceAmountModel { | ||
PriceAmountModel({ | ||
required this.product, | ||
}); | ||
|
||
PriceMetaProduct product; | ||
|
||
String _paidPrice = ''; | ||
String _priceWithoutDiscount = ''; | ||
|
||
set paidPrice(final String value) => _paidPrice = value; | ||
|
||
set priceWithoutDiscount(final String value) => _priceWithoutDiscount = value; | ||
|
||
late double _checkedPaidPrice; | ||
double? _checkedPriceWithoutDiscount; | ||
|
||
double get checkedPaidPrice => _checkedPaidPrice; | ||
|
||
double? get checkedPriceWithoutDiscount => _checkedPriceWithoutDiscount; | ||
|
||
bool promo = false; | ||
|
||
static double? validateDouble(final String value) => | ||
double.tryParse(value) ?? | ||
double.tryParse( | ||
value.replaceAll(',', '.'), | ||
); | ||
|
||
String? checkParameters(final BuildContext context) { | ||
_checkedPaidPrice = validateDouble(_paidPrice)!; | ||
_checkedPriceWithoutDiscount = null; | ||
if (promo) { | ||
if (_priceWithoutDiscount.isNotEmpty) { | ||
_checkedPriceWithoutDiscount = validateDouble(_priceWithoutDiscount); | ||
if (_checkedPriceWithoutDiscount == null) { | ||
return AppLocalizations.of(context).prices_amount_price_incorrect; | ||
} | ||
} | ||
} | ||
return null; | ||
} | ||
} |
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
25 changes: 25 additions & 0 deletions
25
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import 'package:flutter_gen/gen_l10n/app_localizations.dart'; | ||
import 'package:openfoodfacts/openfoodfacts.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; | ||
|
||
final Product? product; | ||
final PriceProduct? priceProduct; | ||
|
||
String get barcode => | ||
product != null ? product!.barcode! : priceProduct!.code; | ||
|
||
String getName(final AppLocalizations appLocalizations) => product != null | ||
? getProductNameAndBrands( | ||
product!, | ||
appLocalizations, | ||
) | ||
: priceProduct!.name ?? priceProduct!.code; | ||
|
||
String? get imageUrl => product != null ? null : priceProduct!.imageURL; | ||
} |
Oops, something went wrong.