From 0e45c574d4d47f82393ca682e319ce98746551a4 Mon Sep 17 00:00:00 2001 From: Edouard Marquez Date: Mon, 20 Jan 2025 19:20:50 +0100 Subject: [PATCH] fix: Hide more interesting photo if nothing is available (#6251) * Hide more interesting photo if nothing is available * The translation is actually used elsewhere --- .../product_image_gallery_other_view.dart | 24 +++++++---- .../product_image_gallery_view.dart | 43 +++++++++++++------ 2 files changed, 46 insertions(+), 21 deletions(-) diff --git a/packages/smooth_app/lib/pages/image/product_image_gallery_other_view.dart b/packages/smooth_app/lib/pages/image/product_image_gallery_other_view.dart index d8eed0d80e39..76a4b1167b0f 100644 --- a/packages/smooth_app/lib/pages/image/product_image_gallery_other_view.dart +++ b/packages/smooth_app/lib/pages/image/product_image_gallery_other_view.dart @@ -23,9 +23,12 @@ double _getSquareSize(final BuildContext context) { /// Display of the other pictures of a product. class ProductImageGalleryOtherView extends StatefulWidget { const ProductImageGalleryOtherView({ + required this.onPhotosAvailable, super.key, }); + final Function(bool hasPhotos) onPhotosAvailable; + @override State createState() => _ProductImageGalleryOtherViewState(); @@ -49,7 +52,9 @@ class _ProductImageGalleryOtherViewState product, ImageSize.DISPLAY, ); + if (rawImages.isNotEmpty) { + widget.onPhotosAvailable(true); return _RawGridGallery(product, rawImages); } final double squareSize = _getSquareSize(context); @@ -61,10 +66,12 @@ class _ProductImageGalleryOtherViewState ) { if (snapshot.connectionState != ConnectionState.done) { return SliverToBoxAdapter( - child: SizedBox( - width: squareSize, - height: squareSize, - child: const CircularProgressIndicator.adaptive(), + child: Center( + child: SizedBox( + width: squareSize, + height: squareSize, + child: const CircularProgressIndicator.adaptive(), + ), ), ); } @@ -84,16 +91,15 @@ class _ProductImageGalleryOtherViewState ); } if (rawImages.isNotEmpty) { + widget.onPhotosAvailable(true); return _RawGridGallery( fetchedProduct.product ?? product, rawImages, ); } - return SliverToBoxAdapter( - child: Text( - appLocalizations.edit_photo_select_existing_downloaded_none, - ), - ); + + widget.onPhotosAvailable(false); + return const SliverToBoxAdapter(child: EMPTY_WIDGET); }, ); } diff --git a/packages/smooth_app/lib/pages/product/gallery_view/product_image_gallery_view.dart b/packages/smooth_app/lib/pages/product/gallery_view/product_image_gallery_view.dart index 6ad583f0a44f..00c84f81cb8e 100644 --- a/packages/smooth_app/lib/pages/product/gallery_view/product_image_gallery_view.dart +++ b/packages/smooth_app/lib/pages/product/gallery_view/product_image_gallery_view.dart @@ -77,6 +77,7 @@ class _ProductImageGalleryViewState extends State late OpenFoodFactsLanguage _language; late final List _mainImageFields; bool _clickedOtherPictureButton = false; + bool _hideOtherPhotos = false; @override void initState() { @@ -177,21 +178,30 @@ class _ProductImageGalleryViewState extends State ), ), ), - SliverPadding( - padding: const EdgeInsetsDirectional.symmetric( - vertical: MEDIUM_SPACE, - horizontal: SMALL_SPACE, - ), - sliver: SliverToBoxAdapter( - child: Text( - appLocalizations.more_photos, - style: - Theme.of(context).textTheme.displayMedium, + if (!_hideOtherPhotos) + SliverPadding( + padding: const EdgeInsetsDirectional.symmetric( + vertical: MEDIUM_SPACE, + horizontal: SMALL_SPACE, + ), + sliver: SliverToBoxAdapter( + child: _moreInterestingPhotoWidget( + appLocalizations, + context, + ), ), ), - ), if (_shouldDisplayRawGallery()) - const ProductImageGalleryOtherView() + ProductImageGalleryOtherView( + onPhotosAvailable: (bool hasPhotos) { + if (_hideOtherPhotos != hasPhotos) { + onNextFrame( + () => setState( + () => _hideOtherPhotos = !hasPhotos, + ), + ); + } + }) else SliverToBoxAdapter( child: Padding( @@ -236,6 +246,15 @@ class _ProductImageGalleryViewState extends State ); } + Text _moreInterestingPhotoWidget( + AppLocalizations appLocalizations, + BuildContext context, + ) => + Text( + appLocalizations.more_photos, + style: Theme.of(context).textTheme.displayMedium, + ); + bool _shouldDisplayRawGallery() => _clickedOtherPictureButton || (upToDateProduct.getRawImages()?.isNotEmpty == true);