Skip to content

Commit

Permalink
Fix: Refresh product on image upload from new product page (#1039)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasmeet0817 authored Jan 28, 2022
1 parent 8947dee commit 173b7fc
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
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

0 comments on commit 173b7fc

Please sign in to comment.