Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Refresh product on image upload from new product page #1039

Merged
merged 1 commit into from
Jan 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ class ImageUploadCard extends StatefulWidget {
this.imageUrl,
this.title,
required this.buttonText,
required this.onUpload,
});

final Product product;
final ImageField imageField;
final String? imageUrl;
final String? title;
final String buttonText;
final Function(BuildContext) onUpload;

@override
State<ImageUploadCard> createState() => _ImageUploadCardState();
Expand Down Expand Up @@ -73,6 +75,7 @@ class _ImageUploadCardState extends State<ImageUploadCard> {
throw Exception(
'image could not be uploaded: ${result.error} ${result.imageId.toString()}');
}
widget.onUpload(context);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@ import 'package:openfoodfacts/model/ProductImage.dart';
import 'package:smooth_app/cards/data_cards/image_upload_card.dart';

class ProductImageCarousel extends StatelessWidget {
const ProductImageCarousel(this.product, {required this.height});
const ProductImageCarousel(
this.product, {
required this.height,
required this.onUpload,
});

final Product product;
final double height;
final Function(BuildContext) onUpload;

@override
Widget build(BuildContext context) {
Expand All @@ -20,34 +25,39 @@ class ProductImageCarousel extends StatelessWidget {
imageUrl: product.imageFrontUrl,
title: appLocalizations.product,
buttonText: appLocalizations.front_photo,
onUpload: onUpload,
),
ImageUploadCard(
product: product,
imageField: ImageField.INGREDIENTS,
imageUrl: product.imageIngredientsUrl,
title: appLocalizations.ingredients,
buttonText: appLocalizations.ingredients_photo,
onUpload: onUpload,
),
ImageUploadCard(
product: product,
imageField: ImageField.NUTRITION,
imageUrl: product.imageNutritionUrl,
title: appLocalizations.nutrition,
buttonText: appLocalizations.nutrition_facts_photo,
onUpload: onUpload,
),
ImageUploadCard(
product: product,
imageField: ImageField.PACKAGING,
imageUrl: product.imagePackagingUrl,
title: appLocalizations.packaging_information,
buttonText: appLocalizations.packaging_information_photo,
onUpload: onUpload,
),
ImageUploadCard(
product: product,
imageField: ImageField.OTHER,
imageUrl: null,
title: appLocalizations.more_photos,
buttonText: appLocalizations.more_photos,
onUpload: onUpload,
),
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,11 @@ class _QuestionCardState extends State<QuestionCard>
),
child: Column(
children: <Widget>[
ProductImageCarousel(widget.product, height: screenSize.height / 6),
ProductImageCarousel(
widget.product,
height: screenSize.height / 6,
onUpload: (_) {},
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: SMALL_SPACE),
child: Column(
Expand Down
6 changes: 5 additions & 1 deletion packages/smooth_app/lib/pages/product/new_product_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,11 @@ class _ProductPageState extends State<ProductPage> {
Align(
heightFactor: 0.7,
alignment: Alignment.topLeft,
child: ProductImageCarousel(_product, height: 200),
child: ProductImageCarousel(
_product,
height: 200,
onUpload: _refreshProduct,
),
),
Padding(
padding: const EdgeInsets.symmetric(
Expand Down