Files
smooth-app/packages/smooth_app/lib/helpers/image_field_extension.dart
monsieurtanuki a8366fd49f feat: 3897 - no language selector for gallery, only for swipeable page (#3924)
* feat: 3897 - no language selector for gallery, only for swipeable page

Main changes:
* `app_en.arb`: added 2 translations ("no image" / "no image for that language")
* `app_fr.arb`: added 2 translations ("no image" / "no image for that language")
* `nutrition_page_loaded.dart`: removed an implicit `language` parameter
* `product_cards_helper.dart`: refactoring
* `product_image_gallery_view.dart`: removed the language selector
* `product_image_swipeable_view.dart`: removed the language parameter; now we always start with the app language
* `product_image_viewer.dart`: now always displays the (non) image for the specified language, with additional labels; added explicit `language` parameters
* `transient_file.dart`: new method `getImageLanguages`

Added explicit `language` parameters for:
* `add_new_product_page.dart`: added an explicit `language` parameter
* `background_task_crop.dart`: added an explicit `language` parameter
* `background_task_image.dart`: added an explicit `language` parameter
* `background_task_unselect.dart`: added an explicit `language` parameter
* `edit_ingredients_page.dart`: added an explicit `language` parameter
* `edit_new_packagings.dart`: added an explicit `language` parameter
* `image_crop_page.dart`: added an explicit `language` parameter
* `image_upload_card.dart`: added an explicit `language` parameter
* `new_crop_page.dart`: added an explicit `language` parameter
* `product_image_local_button.dart`: added an explicit `language` parameter
* `product_image_server_button.dart`: added an explicit `language` parameter
* `uploaded_image_gallery.dart`: added an explicit `language` parameter

* feat: 3897 - slightly related refactoring around ImageFieldSmoothieExtension

* feat: 3897 - minor fix for TEST env
2023-04-30 18:34:35 +02:00

116 lines
3.6 KiB
Dart

import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:openfoodfacts/openfoodfacts.dart';
extension ImageFieldSmoothieExtension on ImageField {
static const List<ImageField> orderedMain = <ImageField>[
ImageField.FRONT,
ImageField.INGREDIENTS,
ImageField.NUTRITION,
ImageField.PACKAGING,
];
static const List<ImageField> orderedAll = <ImageField>[
ImageField.FRONT,
ImageField.INGREDIENTS,
ImageField.NUTRITION,
ImageField.PACKAGING,
ImageField.OTHER,
];
String? getUrl(final Product product) {
switch (this) {
case ImageField.FRONT:
return product.imageFrontUrl;
case ImageField.INGREDIENTS:
return product.imageIngredientsUrl;
case ImageField.NUTRITION:
return product.imageNutritionUrl;
case ImageField.PACKAGING:
return product.imagePackagingUrl;
case ImageField.OTHER:
return null;
}
}
void setUrl(final Product product, final String url) {
switch (this) {
case ImageField.FRONT:
product.imageFrontUrl = url;
break;
case ImageField.INGREDIENTS:
product.imageIngredientsUrl = url;
break;
case ImageField.NUTRITION:
product.imageNutritionUrl = url;
break;
case ImageField.PACKAGING:
product.imagePackagingUrl = url;
break;
case ImageField.OTHER:
// We do nothing.
}
}
String getProductImageButtonText(final AppLocalizations appLocalizations) {
switch (this) {
case ImageField.FRONT:
return appLocalizations.front_photo;
case ImageField.INGREDIENTS:
return appLocalizations.ingredients_photo;
case ImageField.NUTRITION:
return appLocalizations.nutrition_facts_photo;
case ImageField.PACKAGING:
return appLocalizations.packaging_information_photo;
case ImageField.OTHER:
return appLocalizations.more_photos;
}
}
/// Returns a verbose description of the image field.
String getImagePageTitle(final AppLocalizations appLocalizations) {
switch (this) {
case ImageField.FRONT:
return appLocalizations.front_packaging_photo_title;
case ImageField.INGREDIENTS:
return appLocalizations.ingredients_photo_title;
case ImageField.NUTRITION:
return appLocalizations.nutritional_facts_photo_title;
case ImageField.PACKAGING:
return appLocalizations.recycling_photo_title;
case ImageField.OTHER:
return appLocalizations.other_interesting_photo_title;
}
}
/// Returns a compact description of the image field.
String getProductImageTitle(final AppLocalizations appLocalizations) {
switch (this) {
case ImageField.FRONT:
return appLocalizations.product;
case ImageField.INGREDIENTS:
return appLocalizations.ingredients;
case ImageField.NUTRITION:
return appLocalizations.nutrition;
case ImageField.PACKAGING:
return appLocalizations.packaging_information;
case ImageField.OTHER:
return appLocalizations.more_photos;
}
}
String getAddPhotoButtonText(final AppLocalizations appLocalizations) {
switch (this) {
case ImageField.FRONT:
return appLocalizations.front_packaging_photo_button_label;
case ImageField.INGREDIENTS:
return appLocalizations.ingredients_photo_button_label;
case ImageField.NUTRITION:
return appLocalizations.nutritional_facts_photo_button_label;
case ImageField.PACKAGING:
return appLocalizations.recycling_photo_button_label;
case ImageField.OTHER:
return appLocalizations.other_interesting_photo_button_label;
}
}
}