From 3135da5eb2f7a7105c2aa7e6df0380431bce2543 Mon Sep 17 00:00:00 2001 From: rodepanda7 Date: Wed, 9 Oct 2024 22:10:53 +0200 Subject: [PATCH 1/3] faster image transitions and fix zoom out issue --- lib/ui/widgets/cached_image.dart | 6 ++++-- lib/ui/widgets/gallery.dart | 13 +++++++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/ui/widgets/cached_image.dart b/lib/ui/widgets/cached_image.dart index eaae7176c..0efaa486c 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 b47fd65b1..5907497c2 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}); @@ -169,9 +170,13 @@ 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, + // placeholder: + // 'assets/img/photo_placeholder_${(360 - photos[i].rotation) % 360}.png'), + )), ); } else { child = const Center( @@ -181,7 +186,7 @@ class _GalleryState extends State return PhotoViewGalleryPageOptions.customChild( child: child, - minScale: PhotoViewComputedScale.contained * 0.8, + minScale: PhotoViewComputedScale.contained * 1, maxScale: PhotoViewComputedScale.covered * 2, ); }, From 9d9524b8f4b15f621520af59d4d29e1e9be8961b Mon Sep 17 00:00:00 2001 From: rodepanda7 Date: Wed, 6 Nov 2024 19:15:24 +0100 Subject: [PATCH 2/3] remove unnecessary comment --- lib/ui/widgets/gallery.dart | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/ui/widgets/gallery.dart b/lib/ui/widgets/gallery.dart index 5907497c2..4b7232f51 100644 --- a/lib/ui/widgets/gallery.dart +++ b/lib/ui/widgets/gallery.dart @@ -174,8 +174,6 @@ class _GalleryState extends State child: CachedImage( imageUrl: photos[i].full, fit: BoxFit.contain, - // placeholder: - // 'assets/img/photo_placeholder_${(360 - photos[i].rotation) % 360}.png'), )), ); } else { From f084e1c9f85d422786c19b43d308641da70c92b0 Mon Sep 17 00:00:00 2001 From: rodepanda7 Date: Wed, 6 Nov 2024 20:55:43 +0100 Subject: [PATCH 3/3] fix double click unlikes --- lib/ui/widgets/gallery.dart | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/lib/ui/widgets/gallery.dart b/lib/ui/widgets/gallery.dart index 4b7232f51..9a9f3ec0e 100644 --- a/lib/ui/widgets/gallery.dart +++ b/lib/ui/widgets/gallery.dart @@ -122,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(); @@ -241,7 +258,7 @@ class _GalleryState extends State widget.initialPage, widget.photos, widget.photoAmount, - _likePhoto, + _toggleLikePhoto, _loadMorePhotos, ), ), @@ -298,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( @@ -306,7 +323,7 @@ class _PageCounter extends StatefulWidget { this.initialPage, this.photos, this.photoAmount, - this.likePhoto, + this.toggleLikePhoto, this.loadMorePhotos, ); @@ -366,7 +383,7 @@ class __PageCounterState extends State<_PageCounter> { photo.liked ? Icons.favorite : Icons.favorite_outline, ), onPressed: () { - widget.likePhoto( + widget.toggleLikePhoto( widget.photos, currentIndex, );