Skip to content

Commit

Permalink
feat: upgrade to off-dart 3.18.0 (#5973)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
monsieurtanuki authored Nov 30, 2024
1 parent 12b3c48 commit 3aadddf
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 51 deletions.
4 changes: 2 additions & 2 deletions packages/smooth_app/lib/pages/locations/osm_location.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion packages/smooth_app/lib/pages/prices/price_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
66 changes: 21 additions & 45 deletions packages/smooth_app/lib/pages/product/common/product_refresher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -175,62 +176,37 @@ class ProductRefresher {
return localProduct?.productType;
}

/// Returns the list of types to use for that barcode.
Future<List<ProductType>> getOrderedProductTypes({
required final LocalDatabase localDatabase,
required final String barcode,
}) async {
final List<ProductType> result = <ProductType>[];
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.
Future<FetchedProduct> silentFetchAndRefresh({
required final LocalDatabase localDatabase,
required final String barcode,
}) async {
final List<ProductType> 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) {
Expand Down
1 change: 1 addition & 0 deletions packages/smooth_app/lib/query/product_query.dart
Original file line number Diff line number Diff line change
Expand Up @@ -293,5 +293,6 @@ abstract class ProductQuery {
ProductField.WEBSITE,
ProductField.OBSOLETE,
ProductField.OWNER_FIELDS,
ProductField.OWNER,
];
}
4 changes: 2 additions & 2 deletions packages/smooth_app/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion packages/smooth_app/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ dependencies:
path: ../scanner/zxing


openfoodfacts: 3.17.1
openfoodfacts: 3.18.0
# openfoodfacts:
# path: ../../../openfoodfacts-dart

Expand Down

0 comments on commit 3aadddf

Please sign in to comment.