Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix: reset scale on delete #52

Merged
merged 1 commit into from
Oct 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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