diff --git a/lib/pages/image_page.dart b/lib/pages/image_page.dart index e23ffa9..6f7d32e 100644 --- a/lib/pages/image_page.dart +++ b/lib/pages/image_page.dart @@ -5,6 +5,7 @@ import 'dart:math'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:photo_manager/photo_manager.dart'; +import 'package:photo_view/photo_view.dart'; import 'package:photo_view/photo_view_gallery.dart'; import 'package:nothing_gallery/main.dart'; @@ -39,6 +40,7 @@ class _ImagePageWidgetState extends State List images = []; bool decorationVisible = true; + late PhotoViewController photoViewController; late AnimationController animationController; late Animation fadeAnimation; StreamSubscription? eventSubscription; @@ -54,6 +56,7 @@ class _ImagePageWidgetState extends State animationController = AnimationController( vsync: this, duration: const Duration(milliseconds: 500)); + photoViewController = PhotoViewController(); fadeAnimation = Tween(begin: 0, end: 1).animate(animationController); eventSubscription = @@ -77,6 +80,13 @@ class _ImagePageWidgetState extends State images.removeAt(index); imageTotal -= 1; + Size orientatedSize = images[index].orientatedSize; + + double newScale = min( + MediaQuery.of(context).size.width / orientatedSize.width, + MediaQuery.of(context).size.height / orientatedSize.height); + photoViewController.updateMultiple(scale: newScale); + setState(() {}); break; default: @@ -96,6 +106,7 @@ class _ImagePageWidgetState extends State void dispose() { super.dispose(); animationController.dispose(); + photoViewController.dispose(); eventSubscription?.cancel(); toggleStatusBar(true); } @@ -103,6 +114,7 @@ class _ImagePageWidgetState extends State PhotoViewGalleryPageOptions _buildItem(BuildContext context, int index) { Size orientatedSize = images[index].orientatedSize; return PhotoViewGalleryPageOptions( + controller: photoViewController, minScale: min(MediaQuery.of(context).size.width / orientatedSize.width, MediaQuery.of(context).size.height / orientatedSize.height), imageProvider: AssetEntityImage(