Skip to content

Commit

Permalink
fix: Hide more interesting photo if nothing is available (#6251)
Browse files Browse the repository at this point in the history
* Hide more interesting photo if nothing is available

* The translation is actually used elsewhere
  • Loading branch information
g123k authored Jan 20, 2025
1 parent a0fb228 commit 0e45c57
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<ProductImageGalleryOtherView> createState() =>
_ProductImageGalleryOtherViewState();
Expand All @@ -49,7 +52,9 @@ class _ProductImageGalleryOtherViewState
product,
ImageSize.DISPLAY,
);

if (rawImages.isNotEmpty) {
widget.onPhotosAvailable(true);
return _RawGridGallery(product, rawImages);
}
final double squareSize = _getSquareSize(context);
Expand All @@ -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(),
),
),
);
}
Expand All @@ -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);
},
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class _ProductImageGalleryViewState extends State<ProductImageGalleryView>
late OpenFoodFactsLanguage _language;
late final List<ImageField> _mainImageFields;
bool _clickedOtherPictureButton = false;
bool _hideOtherPhotos = false;

@override
void initState() {
Expand Down Expand Up @@ -177,21 +178,30 @@ class _ProductImageGalleryViewState extends State<ProductImageGalleryView>
),
),
),
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(
Expand Down Expand Up @@ -236,6 +246,15 @@ class _ProductImageGalleryViewState extends State<ProductImageGalleryView>
);
}

Text _moreInterestingPhotoWidget(
AppLocalizations appLocalizations,
BuildContext context,
) =>
Text(
appLocalizations.more_photos,
style: Theme.of(context).textTheme.displayMedium,
);

bool _shouldDisplayRawGallery() =>
_clickedOtherPictureButton ||
(upToDateProduct.getRawImages()?.isNotEmpty == true);
Expand Down

0 comments on commit 0e45c57

Please sign in to comment.