From b880ec1d9e61f6dad102c2f19c910c558fa6f4b8 Mon Sep 17 00:00:00 2001 From: monsieurtanuki Date: Sat, 30 Nov 2024 09:51:37 +0100 Subject: [PATCH] feat: upgrade to off-dart 3.18.0 Impacted files: * `osm_location.dart`: minor refactoring due to 3.18.0 - now we may have proofs without osm location (e.g. internet) * `price_model.dart`: minor refactoring due to 3.18.0 - now we may have proofs without osm location (e.g. internet) * `product_query.dart`: added the `OWNER` product field to be retrieved * `product_refresher.dart`: now we use only the `food` server for single barcode queries, but with `ProductTypeFilter.all` * `pubspec.lock`: wtf * `pubspec.yaml`: upgraded to off-dart 3.18.0 --- .../lib/pages/locations/osm_location.dart | 4 +- .../lib/pages/prices/price_model.dart | 2 +- .../product/common/product_refresher.dart | 66 ++++++------------- .../smooth_app/lib/query/product_query.dart | 1 + packages/smooth_app/pubspec.lock | 4 +- packages/smooth_app/pubspec.yaml | 2 +- 6 files changed, 28 insertions(+), 51 deletions(-) diff --git a/packages/smooth_app/lib/pages/locations/osm_location.dart b/packages/smooth_app/lib/pages/locations/osm_location.dart index d66733e76c94..a17e8cb5aecf 100644 --- a/packages/smooth_app/lib/pages/locations/osm_location.dart +++ b/packages/smooth_app/lib/pages/locations/osm_location.dart @@ -19,8 +19,8 @@ class OsmLocation { }); OsmLocation.fromPrice(final Location location) - : osmId = location.osmId, - osmType = location.type, + : osmId = location.osmId!, + osmType = location.type!, longitude = location.longitude ?? 0, latitude = location.latitude ?? 0, name = location.name, diff --git a/packages/smooth_app/lib/pages/prices/price_model.dart b/packages/smooth_app/lib/pages/prices/price_model.dart index c4193e077de5..032af36cdd85 100644 --- a/packages/smooth_app/lib/pages/prices/price_model.dart +++ b/packages/smooth_app/lib/pages/prices/price_model.dart @@ -144,7 +144,7 @@ class PriceModel with ChangeNotifier { notifyListeners(); } - OsmLocation? get location => proof != null + OsmLocation? get location => proof?.location?.osmId != null ? OsmLocation.fromPrice(proof!.location!) : _locations!.firstOrNull; diff --git a/packages/smooth_app/lib/pages/product/common/product_refresher.dart b/packages/smooth_app/lib/pages/product/common/product_refresher.dart index cd5b32fd2b9b..55f87dd8eb75 100644 --- a/packages/smooth_app/lib/pages/product/common/product_refresher.dart +++ b/packages/smooth_app/lib/pages/product/common/product_refresher.dart @@ -84,6 +84,7 @@ class ProductRefresher { language: language, country: ProductQuery.getCountry(), version: ProductQuery.productQueryVersion, + productTypeFilter: ProductTypeFilter.all, ); /// Returns the standard configuration for several barcodes product query. @@ -175,27 +176,6 @@ class ProductRefresher { return localProduct?.productType; } - /// Returns the list of types to use for that barcode. - Future> getOrderedProductTypes({ - required final LocalDatabase localDatabase, - required final String barcode, - }) async { - final List result = []; - final ProductType? productType = await getCurrentProductType( - localDatabase: localDatabase, - barcode: barcode, - ); - if (productType != null) { - result.add(productType); - } - for (final ProductType value in ProductType.values) { - if (!result.contains(value)) { - result.add(value); - } - } - return result; - } - /// Fetches the product from the server and refreshes the local database. /// /// Silent version. @@ -203,34 +183,30 @@ class ProductRefresher { required final LocalDatabase localDatabase, required final String barcode, }) async { - final List productTypes = await getOrderedProductTypes( - localDatabase: localDatabase, - barcode: barcode, + // Now we let "food" redirect the queries if needed, as we use + // ProductTypeFilter.all + const ProductType productType = ProductType.food; + final UriProductHelper uriProductHelper = ProductQuery.getUriProductHelper( + productType: productType, ); - late UriProductHelper uriProductHelper; - final OpenFoodFactsLanguage language = ProductQuery.getLanguage(); try { - for (final ProductType productType in productTypes) { - uriProductHelper = ProductQuery.getUriProductHelper( + final OpenFoodFactsLanguage language = ProductQuery.getLanguage(); + final ProductResultV3 result = await OpenFoodAPIClient.getProductV3( + getBarcodeQueryConfiguration( + barcode, + language, + ), + uriHelper: uriProductHelper, + user: ProductQuery.getReadUser(), + ); + if (result.product != null) { + await DaoProduct(localDatabase).put( + result.product!, + language, productType: productType, ); - final ProductResultV3 result = await OpenFoodAPIClient.getProductV3( - getBarcodeQueryConfiguration( - barcode, - language, - ), - uriHelper: uriProductHelper, - user: ProductQuery.getReadUser(), - ); - if (result.product != null) { - await DaoProduct(localDatabase).put( - result.product!, - language, - productType: productType, - ); - localDatabase.upToDate.setLatestDownloadedProduct(result.product!); - return FetchedProduct.found(result.product!); - } + localDatabase.upToDate.setLatestDownloadedProduct(result.product!); + return FetchedProduct.found(result.product!); } return const FetchedProduct.internetNotFound(); } catch (e) { diff --git a/packages/smooth_app/lib/query/product_query.dart b/packages/smooth_app/lib/query/product_query.dart index 57c776c4f909..1a71fb7f3d09 100644 --- a/packages/smooth_app/lib/query/product_query.dart +++ b/packages/smooth_app/lib/query/product_query.dart @@ -293,5 +293,6 @@ abstract class ProductQuery { ProductField.WEBSITE, ProductField.OBSOLETE, ProductField.OWNER_FIELDS, + ProductField.OWNER, ]; } diff --git a/packages/smooth_app/pubspec.lock b/packages/smooth_app/pubspec.lock index a361a63c91c6..406ffb608bcb 100644 --- a/packages/smooth_app/pubspec.lock +++ b/packages/smooth_app/pubspec.lock @@ -1076,10 +1076,10 @@ packages: dependency: "direct main" description: name: openfoodfacts - sha256: "0ad8ac186a09427d74567460bbcdb1a984afd2558a172afaab87825f0bfec026" + sha256: "2a2076e5190e4b573ce5326cd4981ebdefa33c57c0507ca0057c57c12b79c47a" url: "https://pub.dev" source: hosted - version: "3.17.1" + version: "3.18.0" openfoodfacts_flutter_lints: dependency: "direct dev" description: diff --git a/packages/smooth_app/pubspec.yaml b/packages/smooth_app/pubspec.yaml index a5256ab59f41..d77edb541988 100644 --- a/packages/smooth_app/pubspec.yaml +++ b/packages/smooth_app/pubspec.yaml @@ -99,7 +99,7 @@ dependencies: path: ../scanner/zxing - openfoodfacts: 3.17.1 + openfoodfacts: 3.18.0 # openfoodfacts: # path: ../../../openfoodfacts-dart