diff --git a/lib/ui/widgets/cached_image.dart b/lib/ui/widgets/cached_image.dart index eaae7176..0efaa486 100644 --- a/lib/ui/widgets/cached_image.dart +++ b/lib/ui/widgets/cached_image.dart @@ -10,12 +10,14 @@ class CachedImage extends CachedNetworkImage { BoxFit super.fit = BoxFit.cover, Duration super.fadeOutDuration = const Duration(milliseconds: 200), super.fadeInDuration = const Duration(milliseconds: 200), - required String placeholder, + String? placeholder, }) : super( key: ValueKey(imageUrl), cacheManager: cache.ThaliaCacheManager(), cacheKey: _getCacheKey(imageUrl), - placeholder: (_, __) => Image.asset(placeholder, fit: fit), + placeholder: placeholder == null + ? null + : (_, __) => Image.asset(placeholder, fit: fit), ); } diff --git a/lib/ui/widgets/gallery.dart b/lib/ui/widgets/gallery.dart index b47fd65b..9a9f3ec0 100644 --- a/lib/ui/widgets/gallery.dart +++ b/lib/ui/widgets/gallery.dart @@ -12,6 +12,7 @@ import 'package:reaxit/models.dart'; import 'package:reaxit/ui/theme.dart'; import 'package:share_plus/share_plus.dart'; import 'package:gal/gal.dart'; +import 'package:reaxit/ui/widgets/cached_image.dart'; abstract class GalleryCubit extends StateStreamableSource { Future updateLike({required bool liked, required int index}); @@ -121,6 +122,23 @@ class _GalleryState extends State } Future _likePhoto(List photos, int index) async { + final messenger = ScaffoldMessenger.of(context); + likeController.forward(); + try { + await BlocProvider.of(context).updateLike( + liked: true, + index: index, + ); + } on ApiException { + messenger.showSnackBar( + const SnackBar( + content: Text('Something went wrong while liking the photo.'), + ), + ); + } + } + + Future _toggleLikePhoto(List photos, int index) async { final messenger = ScaffoldMessenger.of(context); if (photos[index].liked) { unlikeController.forward(); @@ -169,9 +187,11 @@ class _GalleryState extends State child = GestureDetector( onDoubleTap: () => _likePhoto(photos, i), child: RotatedBox( - quarterTurns: photos[i].rotation ~/ 90, - child: Image.network(photos[i].full), - ), + quarterTurns: photos[i].rotation ~/ 90, + child: CachedImage( + imageUrl: photos[i].full, + fit: BoxFit.contain, + )), ); } else { child = const Center( @@ -181,7 +201,7 @@ class _GalleryState extends State return PhotoViewGalleryPageOptions.customChild( child: child, - minScale: PhotoViewComputedScale.contained * 0.8, + minScale: PhotoViewComputedScale.contained * 1, maxScale: PhotoViewComputedScale.covered * 2, ); }, @@ -238,7 +258,7 @@ class _GalleryState extends State widget.initialPage, widget.photos, widget.photoAmount, - _likePhoto, + _toggleLikePhoto, _loadMorePhotos, ), ), @@ -295,7 +315,7 @@ class _PageCounter extends StatefulWidget { final int initialPage; final List photos; final int photoAmount; - final void Function(List photos, int index) likePhoto; + final void Function(List photos, int index) toggleLikePhoto; final void Function() loadMorePhotos; const _PageCounter( @@ -303,7 +323,7 @@ class _PageCounter extends StatefulWidget { this.initialPage, this.photos, this.photoAmount, - this.likePhoto, + this.toggleLikePhoto, this.loadMorePhotos, ); @@ -363,7 +383,7 @@ class __PageCounterState extends State<_PageCounter> { photo.liked ? Icons.favorite : Icons.favorite_outline, ), onPressed: () { - widget.likePhoto( + widget.toggleLikePhoto( widget.photos, currentIndex, );