Skip to content

Commit

Permalink
Merge pull request #52 from jerichoi224/48-reset-zoom-factor-on-image…
Browse files Browse the repository at this point in the history
…-page-on-delete

fix: reset scale on delete
  • Loading branch information
jerichoi224 authored Oct 23, 2023
2 parents 10a4d24 + 3195a40 commit 57d5591
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/pages/image_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -39,6 +40,7 @@ class _ImagePageWidgetState extends State<ImagePageWidget>
List<AssetEntity> images = [];
bool decorationVisible = true;

late PhotoViewController photoViewController;
late AnimationController animationController;
late Animation fadeAnimation;
StreamSubscription? eventSubscription;
Expand All @@ -54,6 +56,7 @@ class _ImagePageWidgetState extends State<ImagePageWidget>

animationController = AnimationController(
vsync: this, duration: const Duration(milliseconds: 500));
photoViewController = PhotoViewController();
fadeAnimation = Tween(begin: 0, end: 1).animate(animationController);

eventSubscription =
Expand All @@ -77,6 +80,13 @@ class _ImagePageWidgetState extends State<ImagePageWidget>
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:
Expand All @@ -96,13 +106,15 @@ class _ImagePageWidgetState extends State<ImagePageWidget>
void dispose() {
super.dispose();
animationController.dispose();
photoViewController.dispose();
eventSubscription?.cancel();
toggleStatusBar(true);
}

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(
Expand Down

0 comments on commit 57d5591

Please # to comment.