From b89e5d6c3f6ef0aa53d0e5aff13025f2f2fa8a32 Mon Sep 17 00:00:00 2001 From: Thibault Deckers Date: Thu, 12 Nov 2020 11:57:39 +0900 Subject: [PATCH] fixed minimap for untiled raw images with different decoded image size --- lib/widgets/fullscreen/image_view.dart | 17 +++++++++++++---- lib/widgets/fullscreen/overlay/minimap.dart | 9 +++++---- pubspec.lock | 2 +- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/lib/widgets/fullscreen/image_view.dart b/lib/widgets/fullscreen/image_view.dart index 6ae604ab7..f79584088 100644 --- a/lib/widgets/fullscreen/image_view.dart +++ b/lib/widgets/fullscreen/image_view.dart @@ -41,6 +41,7 @@ class _ImageViewState extends State { final PhotoViewController _photoViewController = PhotoViewController(); final ValueNotifier _viewStateNotifier = ValueNotifier(ViewState.zero); StreamSubscription _subscription; + Size _photoViewChildSize; static const backgroundDecoration = BoxDecoration(color: Colors.transparent); static const maxScale = 2.0; @@ -53,6 +54,9 @@ class _ImageViewState extends State { void initState() { super.initState(); _subscription = _photoViewController.outputStateStream.listen(_onViewChanged); + if (entry.isVideo || (!entry.isSvg && entry.canDecode && useTile)) { + _photoViewChildSize = entry.displaySize; + } } @override @@ -140,6 +144,10 @@ class _ImageViewState extends State { ), loadFailedChild: _buildError(), backgroundDecoration: backgroundDecoration, + imageSizedCallback: (size) { + // do not directly update the `ViewState` notifier as this callback is called during build + _photoViewChildSize = size; + }, controller: _photoViewController, maxScale: maxScale, minScale: PhotoViewComputedScale.contained, @@ -229,7 +237,7 @@ class _ImageViewState extends State { ); void _onViewChanged(PhotoViewControllerValue v) { - final viewState = ViewState(v.position, v.scale); + final viewState = ViewState(v.position, v.scale, _photoViewChildSize); _viewStateNotifier.value = viewState; ViewStateNotification(entry.uri, viewState).dispatch(context); } @@ -238,14 +246,15 @@ class _ImageViewState extends State { class ViewState { final Offset position; final double scale; + final Size size; - static const ViewState zero = ViewState(Offset(0.0, 0.0), 0); + static const ViewState zero = ViewState(Offset(0.0, 0.0), 0, null); - const ViewState(this.position, this.scale); + const ViewState(this.position, this.scale, this.size); @override String toString() { - return '$runtimeType#${shortHash(this)}{position=$position, scale=$scale}'; + return '$runtimeType#${shortHash(this)}{position=$position, scale=$scale, size=$size}'; } } diff --git a/lib/widgets/fullscreen/overlay/minimap.dart b/lib/widgets/fullscreen/overlay/minimap.dart index 1f76cd247..edceade7c 100644 --- a/lib/widgets/fullscreen/overlay/minimap.dart +++ b/lib/widgets/fullscreen/overlay/minimap.dart @@ -27,12 +27,13 @@ class Minimap extends StatelessWidget { return AnimatedBuilder( animation: viewStateNotifier, builder: (context, child) { + final viewState = viewStateNotifier.value; return CustomPaint( painter: MinimapPainter( - entrySize: entry.displaySize, viewportSize: mqSize, - viewCenterOffset: viewStateNotifier.value.position, - viewScale: viewStateNotifier.value.scale, + entrySize: viewState.size ?? entry.displaySize, + viewCenterOffset: viewState.position, + viewScale: viewState.scale, minimapBorderColor: Colors.white30, ), size: size, @@ -49,8 +50,8 @@ class MinimapPainter extends CustomPainter { final Color minimapBorderColor, viewportBorderColor; const MinimapPainter({ - @required this.entrySize, @required this.viewportSize, + @required this.entrySize, @required this.viewCenterOffset, @required this.viewScale, this.minimapBorderColor = Colors.white, diff --git a/pubspec.lock b/pubspec.lock index cc93261ed..041992b26 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -674,7 +674,7 @@ packages: description: path: "." ref: HEAD - resolved-ref: "79a3c20ee7f01e6ffb71464000c2ca8f1e28ec44" + resolved-ref: aa6400bbc85bf6ce953c4609d126796cdb4ca3c2 url: "git://github.com/deckerst/photo_view.git" source: git version: "0.9.2"