forked from openfoodfacts/openfoodfacts-dart
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 956 - added product owner fields (openfoodfacts#961)
* feat: 956 - added product owner fields New file: * `owner_field.dart`: Helper class to compute the Product.ownerFields tags. Impacted files: * `api_get_product_test.dart`: added a test for owner fields * `openfoodfacts.dart`: added new class `OwnerField` * `product.dart`: added field `ownerFields` and method `getOwnerFieldTimestamp` * `product.g.dart`: generated * `product_fields.dart`: refactored around localized product fields * Unrelated unit test minor fix
- Loading branch information
1 parent
9296ce6
commit bd3202b
Showing
6 changed files
with
364 additions
and
45 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import '../utils/language_helper.dart'; | ||
import '../utils/product_fields.dart'; | ||
import 'nutrient.dart'; | ||
import 'off_tagged.dart'; | ||
|
||
/// Helper class to compute the Product.ownerFields tags. | ||
class OwnerField implements OffTagged { | ||
const OwnerField.raw(this.offTag); | ||
|
||
OwnerField.nutrient(final Nutrient nutrient) : this.raw(nutrient.offTag); | ||
|
||
factory OwnerField.productField( | ||
final ProductField productField, | ||
final OpenFoodFactsLanguage language, | ||
) { | ||
final ProductField? inLanguages = productField.inLanguages; | ||
if (inLanguages == null) { | ||
return OwnerField.raw(productField.offTag); | ||
} | ||
return OwnerField.raw('${inLanguages.offTag}${language.offTag}'); | ||
} | ||
|
||
@override | ||
final String offTag; | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.