Skip to content

Commit

Permalink
feat: 5128 - visible dates on raw image grid items (#5144)
Browse files Browse the repository at this point in the history
Impacted files:
* `product_image_gallery_other_view.dart`: display the upload date on top of raw image grid items
* `product_image_gallery_view.dart`: unrelated minor refactoring
* `pubspec.lock`: wtf
* `pubspec.yaml`: upgrade to off-dart 3.5.0 in order to get the uploaded timestamp of raw images
* `smooth_image.dart`: unrelated minor refactoring
  • Loading branch information
monsieurtanuki authored Apr 8, 2024
1 parent 1014f8a commit 1922d39
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class SmoothImage extends StatelessWidget {
this.width,
this.color,
this.decoration,
this.fit,
this.rounded,
this.fit = BoxFit.cover,
this.rounded = true,
this.heroTag,
});

Expand All @@ -25,17 +25,17 @@ class SmoothImage extends StatelessWidget {
final double? width;
final Color? color;
final Decoration? decoration;
final BoxFit? fit;
final BoxFit fit;
final String? heroTag;
final bool? rounded;
final bool rounded;

@override
Widget build(BuildContext context) {
Widget child = imageProvider == null
? const PictureNotFound()
: Image(
image: imageProvider!,
fit: fit ?? BoxFit.cover,
fit: fit,
loadingBuilder: _loadingBuilder,
errorBuilder: _errorBuilder,
);
Expand All @@ -51,7 +51,7 @@ class SmoothImage extends StatelessWidget {
color: color,
child: child);

if (rounded ?? true) {
if (rounded) {
child = ClipRRect(
borderRadius: ROUNDED_BORDER_RADIUS,
child: child,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import 'package:auto_size_text/auto_size_text.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:intl/intl.dart';
import 'package:openfoodfacts/openfoodfacts.dart';
import 'package:provider/provider.dart';
import 'package:smooth_app/data_models/fetched_product.dart';
import 'package:smooth_app/database/local_database.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/helpers/product_cards_helper.dart';
import 'package:smooth_app/pages/image/product_image_other_page.dart';
Expand Down Expand Up @@ -104,9 +107,12 @@ class _RawGridGallery extends StatelessWidget {
final Product product;
final List<ProductImage> rawImages;

static final DateFormat _dateFormat = DateFormat('yyyy-MM-dd');

@override
Widget build(BuildContext context) {
final double squareSize = _getSquareSize(context);
final DateTime now = DateTime.now();
return SliverGrid(
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: _columns,
Expand All @@ -116,6 +122,22 @@ class _RawGridGallery extends StatelessWidget {
// order by descending ids
index = rawImages.length - 1 - index;
final ProductImage productImage = rawImages[index];
final DateTime? uploaded = productImage.uploaded;
final String? date;
final bool expired;
if (uploaded == null) {
date = null;
expired = false;
} else {
date = _dateFormat.format(uploaded);
expired = now.difference(uploaded).inDays > 365;
}
final Widget image = SmoothImage(
width: squareSize,
height: squareSize,
imageProvider: NetworkImage(productImage.getUrl(product.barcode!)),
rounded: false,
);
return InkWell(
onTap: () async => Navigator.push<void>(
context,
Expand All @@ -126,13 +148,35 @@ class _RawGridGallery extends StatelessWidget {
),
),
),
child: SmoothImage(
width: squareSize,
height: squareSize,
imageProvider: NetworkImage(
productImage.getUrl(product.barcode!),
),
),
child: date == null
? image
: 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,
),
),
),
),
),
),
],
),
);
},
addAutomaticKeepAlives: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ class _PhotoRow extends StatelessWidget {

@override
Widget build(BuildContext context) {
final ImageField imageField = _getImageField(position);
return Padding(
padding: const EdgeInsets.only(
top: SMALL_SPACE,
Expand All @@ -204,17 +205,15 @@ class _PhotoRow extends StatelessWidget {
aspectRatio: 1.0,
child: SmoothImage(
rounded: false,
imageProvider: _getTransientFile(
getImageField(position),
).getImageProvider(),
imageProvider: _getTransientFile(imageField).getImageProvider(),
),
),
Expanded(
child: Center(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
getImageField(position)
imageField
.getProductImageTitle(AppLocalizations.of(context)),
style: Theme.of(context).textTheme.headlineMedium,
textAlign: TextAlign.center,
Expand Down Expand Up @@ -253,6 +252,6 @@ class _PhotoRow extends StatelessWidget {
language,
);

ImageField getImageField(final int index) =>
ImageField _getImageField(final int index) =>
ImageFieldSmoothieExtension.orderedMain[index];
}
4 changes: 2 additions & 2 deletions packages/smooth_app/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1108,10 +1108,10 @@ packages:
dependency: "direct main"
description:
name: openfoodfacts
sha256: "3f60e195c47398bdfddf04944fb9a2b41255d6cc281d5494ad1002843351b569"
sha256: "935d21b873349ec8ecff1018add7523348c769d3a321bed7cd0407e15d691488"
url: "https://pub.dev"
source: hosted
version: "3.4.0"
version: "3.5.0"
openfoodfacts_flutter_lints:
dependency: "direct dev"
description:
Expand Down
2 changes: 1 addition & 1 deletion packages/smooth_app/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ dependencies:
path: ../scanner/zxing


openfoodfacts: 3.4.0
openfoodfacts: 3.5.0
# openfoodfacts:
# path: ../../../openfoodfacts-dart

Expand Down

0 comments on commit 1922d39

Please sign in to comment.