-
-
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: 5323 - generic way to display product images, with timestamp (#…
…5333) New file: * `product_image_widget.dart`: Displays a product image thumbnail with the upload timestamp on top. Impacted files: * `product_image_gallery_other_view.dart`: now using new widget `ProductImageWidget` * `uploaded_image_gallery.dart`: now using new widget `ProductImageWidget`
- Loading branch information
1 parent
1ce24e8
commit c26528c
Showing
3 changed files
with
84 additions
and
81 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
71 changes: 71 additions & 0 deletions
71
packages/smooth_app/lib/pages/image/product_image_widget.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,71 @@ | ||
import 'package:auto_size_text/auto_size_text.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:intl/intl.dart'; | ||
import 'package:openfoodfacts/openfoodfacts.dart'; | ||
import 'package:smooth_app/generic_lib/design_constants.dart'; | ||
import 'package:smooth_app/generic_lib/widgets/images/smooth_image.dart'; | ||
import 'package:smooth_app/query/product_query.dart'; | ||
|
||
/// Displays a product image thumbnail with the upload date on top. | ||
class ProductImageWidget extends StatelessWidget { | ||
const ProductImageWidget({ | ||
required this.productImage, | ||
required this.barcode, | ||
required this.squareSize, | ||
}); | ||
|
||
final ProductImage productImage; | ||
final String barcode; | ||
final double squareSize; | ||
|
||
static final DateFormat _dateFormat = DateFormat('yyyy-MM-dd'); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final Widget image = SmoothImage( | ||
width: squareSize, | ||
height: squareSize, | ||
imageProvider: NetworkImage( | ||
productImage.getUrl( | ||
barcode, | ||
uriHelper: ProductQuery.uriProductHelper, | ||
), | ||
), | ||
rounded: false, | ||
); | ||
final DateTime? uploaded = productImage.uploaded; | ||
if (uploaded == null) { | ||
return image; | ||
} | ||
final DateTime now = DateTime.now(); | ||
final String date = _dateFormat.format(uploaded); | ||
final bool expired = now.difference(uploaded).inDays > 365; | ||
return Stack( | ||
children: <Widget>[ | ||
image, | ||
SizedBox( | ||
width: squareSize, | ||
height: squareSize, | ||
child: Align( | ||
alignment: Alignment.bottomCenter, | ||
child: Padding( | ||
padding: const EdgeInsets.all(SMALL_SPACE), | ||
child: Container( | ||
height: VERY_LARGE_SPACE, | ||
color: expired | ||
? Colors.red.withAlpha(128) | ||
: Colors.white.withAlpha(128), | ||
child: Center( | ||
child: AutoSizeText( | ||
date, | ||
maxLines: 1, | ||
), | ||
), | ||
), | ||
), | ||
), | ||
), | ||
], | ||
); | ||
} | ||
} |
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