-
-
Notifications
You must be signed in to change notification settings - Fork 302
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 4674 - added the "other photos" section (#4866)
* feat: 4674 - added the "other photos" section New files: * `product_image_gallery_other_view.dart`: Display of the other pictures of a product. * `product_image_other_page.dart`: Full page display of a raw product image. Impacted file: * `product_image_gallery_view.dart`: added the "other photos" section; fixed a "refresh not working" bug * feat: 4674 - added a "click button" step * feat: 4674 - different label for button Impacted files: * `app_en.arb`: add new label for "click for other photo" button * `app_fr.arb`: add new label for "click for other photo" button * `product_image_gallery_view.dart`: used new label for "click for other photo" button
- Loading branch information
1 parent
60971d1
commit f0c26da
Showing
5 changed files
with
194 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
packages/smooth_app/lib/pages/image/product_image_gallery_other_view.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_gen/gen_l10n/app_localizations.dart'; | ||
import 'package:openfoodfacts/openfoodfacts.dart'; | ||
import 'package:smooth_app/generic_lib/widgets/images/smooth_image.dart'; | ||
import 'package:smooth_app/pages/image/product_image_other_page.dart'; | ||
import 'package:smooth_app/query/product_query.dart'; | ||
|
||
/// Display of the other pictures of a product. | ||
class ProductImageGalleryOtherView extends StatefulWidget { | ||
const ProductImageGalleryOtherView({ | ||
required this.product, | ||
}); | ||
|
||
final Product product; | ||
|
||
@override | ||
State<ProductImageGalleryOtherView> createState() => | ||
_ProductImageGalleryOtherViewState(); | ||
} | ||
|
||
class _ProductImageGalleryOtherViewState | ||
extends State<ProductImageGalleryOtherView> { | ||
late final Future<List<int>> _loading = _loadOtherPics(); | ||
|
||
/// Number of columns for the grid. | ||
static const int _columns = 3; | ||
|
||
Future<List<int>> _loadOtherPics() async => | ||
OpenFoodAPIClient.getProductImageIds( | ||
widget.product.barcode!, | ||
uriHelper: ProductQuery.uriProductHelper, | ||
user: ProductQuery.getUser(), | ||
); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final AppLocalizations appLocalizations = AppLocalizations.of(context); | ||
final double screenWidth = MediaQuery.of(context).size.width; | ||
final double squareSize = screenWidth / _columns; | ||
return FutureBuilder<List<int>>( | ||
future: _loading, | ||
builder: ( | ||
final BuildContext context, | ||
final AsyncSnapshot<List<int>> snapshot, | ||
) { | ||
if (snapshot.connectionState != ConnectionState.done) { | ||
return SizedBox( | ||
width: squareSize, | ||
height: squareSize, | ||
child: const CircularProgressIndicator.adaptive(), | ||
); | ||
} | ||
if (snapshot.data == null) { | ||
return Text( | ||
snapshot.error?.toString() ?? | ||
appLocalizations.loading_dialog_default_error_message, | ||
); | ||
} | ||
final List<int> ids = snapshot.data!; | ||
if (ids.isEmpty) { | ||
// very unlikely btw. | ||
return Text( | ||
appLocalizations.edit_photo_select_existing_downloaded_none, | ||
); | ||
} | ||
return SizedBox( | ||
height: (ids.length / _columns).ceil() * squareSize, | ||
child: GridView.builder( | ||
physics: const NeverScrollableScrollPhysics(), | ||
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount( | ||
crossAxisCount: _columns, | ||
), | ||
itemBuilder: (final BuildContext context, final int index) => | ||
InkWell( | ||
onTap: () async => Navigator.push<void>( | ||
context, | ||
MaterialPageRoute<bool>( | ||
builder: (BuildContext context) => ProductImageOtherPage( | ||
widget.product, | ||
ids[index], | ||
), | ||
), | ||
), | ||
child: SmoothImage( | ||
width: squareSize, | ||
height: squareSize, | ||
imageProvider: NetworkImage( | ||
ImageHelper.getUploadedImageUrl( | ||
widget.product.barcode!, | ||
ids[index], | ||
ImageSize.DISPLAY, | ||
), | ||
), | ||
), | ||
), | ||
itemCount: ids.length, | ||
//scrollDirection: Axis.vertical, | ||
), | ||
); | ||
}, | ||
); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
packages/smooth_app/lib/pages/image/product_image_other_page.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_gen/gen_l10n/app_localizations.dart'; | ||
import 'package:openfoodfacts/openfoodfacts.dart'; | ||
import 'package:smooth_app/helpers/product_cards_helper.dart'; | ||
import 'package:smooth_app/widgets/smooth_app_bar.dart'; | ||
import 'package:smooth_app/widgets/smooth_scaffold.dart'; | ||
|
||
/// Full page display of a raw product image. | ||
class ProductImageOtherPage extends StatelessWidget { | ||
const ProductImageOtherPage( | ||
this.product, | ||
this.imageId, | ||
); | ||
|
||
final Product product; | ||
final int imageId; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final AppLocalizations appLocalizations = AppLocalizations.of(context); | ||
return SmoothScaffold( | ||
appBar: SmoothAppBar( | ||
centerTitle: false, | ||
title: Text(appLocalizations.edit_product_form_item_photos_title), | ||
subTitle: buildProductTitle(product, appLocalizations), | ||
), | ||
body: Image( | ||
image: NetworkImage( | ||
ImageHelper.getUploadedImageUrl( | ||
product.barcode!, | ||
imageId, | ||
ImageSize.ORIGINAL, | ||
), | ||
), | ||
fit: BoxFit.cover, | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters