Files
smooth-app/packages/smooth_app/lib/helpers/image_field_extension.dart
monsieurtanuki 558034fb6f feat: 3897 - mutilingual gallery and swipeable images - read only (#3917)
New file:
* `image_field_extension.dart`: moved code from `product_cards_helper.dart`

Deleted files:
* `product_image_unswipeable_view.dart`
* `smooth_images_sliver_list.dart`
* `smooth_images_view.dart`

Impacted files:
* `image_upload_card.dart`: minor refactoring
* `language_selector.dart`: added an optional foreground color (use case: explicit white for images on a black background)
* `new_crop_page.dart`: minor refactoring
* `nutrition_page_loaded.dart: now using a new special case constructor of `ProductImageSwipeableView` instead of now deleted `ProductImageUnswipeableView`
* `product_cards_helper.dart`: added language-related methods; refactored
* `product_image_carousel.dart`: minor refactoring
* `product_image_data.dart`: added language
* `product_image_gallery_view.dart`: simplified the display of the 4 images; added the language selector on top; refactored the title
* `product_image_swipeable_view.dart`: now handles the "mono imagefield" case; now manages languages; minor refactoring
* `product_image_viewer.dart`: added the language selector; removed the irrelevant `Scaffold`
2023-04-29 13:56:36 +02:00

74 lines
2.4 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,
];
String? getImageFieldUrl(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;
}
}
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;
}
}
}