fixed minimap for untiled raw images with different decoded image size
This commit is contained in:
parent
c410f83b6d
commit
b89e5d6c3f
3 changed files with 19 additions and 9 deletions
|
@ -41,6 +41,7 @@ class _ImageViewState extends State<ImageView> {
|
||||||
final PhotoViewController _photoViewController = PhotoViewController();
|
final PhotoViewController _photoViewController = PhotoViewController();
|
||||||
final ValueNotifier<ViewState> _viewStateNotifier = ValueNotifier<ViewState>(ViewState.zero);
|
final ValueNotifier<ViewState> _viewStateNotifier = ValueNotifier<ViewState>(ViewState.zero);
|
||||||
StreamSubscription<PhotoViewControllerValue> _subscription;
|
StreamSubscription<PhotoViewControllerValue> _subscription;
|
||||||
|
Size _photoViewChildSize;
|
||||||
|
|
||||||
static const backgroundDecoration = BoxDecoration(color: Colors.transparent);
|
static const backgroundDecoration = BoxDecoration(color: Colors.transparent);
|
||||||
static const maxScale = 2.0;
|
static const maxScale = 2.0;
|
||||||
|
@ -53,6 +54,9 @@ class _ImageViewState extends State<ImageView> {
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
_subscription = _photoViewController.outputStateStream.listen(_onViewChanged);
|
_subscription = _photoViewController.outputStateStream.listen(_onViewChanged);
|
||||||
|
if (entry.isVideo || (!entry.isSvg && entry.canDecode && useTile)) {
|
||||||
|
_photoViewChildSize = entry.displaySize;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -140,6 +144,10 @@ class _ImageViewState extends State<ImageView> {
|
||||||
),
|
),
|
||||||
loadFailedChild: _buildError(),
|
loadFailedChild: _buildError(),
|
||||||
backgroundDecoration: backgroundDecoration,
|
backgroundDecoration: backgroundDecoration,
|
||||||
|
imageSizedCallback: (size) {
|
||||||
|
// do not directly update the `ViewState` notifier as this callback is called during build
|
||||||
|
_photoViewChildSize = size;
|
||||||
|
},
|
||||||
controller: _photoViewController,
|
controller: _photoViewController,
|
||||||
maxScale: maxScale,
|
maxScale: maxScale,
|
||||||
minScale: PhotoViewComputedScale.contained,
|
minScale: PhotoViewComputedScale.contained,
|
||||||
|
@ -229,7 +237,7 @@ class _ImageViewState extends State<ImageView> {
|
||||||
);
|
);
|
||||||
|
|
||||||
void _onViewChanged(PhotoViewControllerValue v) {
|
void _onViewChanged(PhotoViewControllerValue v) {
|
||||||
final viewState = ViewState(v.position, v.scale);
|
final viewState = ViewState(v.position, v.scale, _photoViewChildSize);
|
||||||
_viewStateNotifier.value = viewState;
|
_viewStateNotifier.value = viewState;
|
||||||
ViewStateNotification(entry.uri, viewState).dispatch(context);
|
ViewStateNotification(entry.uri, viewState).dispatch(context);
|
||||||
}
|
}
|
||||||
|
@ -238,14 +246,15 @@ class _ImageViewState extends State<ImageView> {
|
||||||
class ViewState {
|
class ViewState {
|
||||||
final Offset position;
|
final Offset position;
|
||||||
final double scale;
|
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
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
return '$runtimeType#${shortHash(this)}{position=$position, scale=$scale}';
|
return '$runtimeType#${shortHash(this)}{position=$position, scale=$scale, size=$size}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,12 +27,13 @@ class Minimap extends StatelessWidget {
|
||||||
return AnimatedBuilder(
|
return AnimatedBuilder(
|
||||||
animation: viewStateNotifier,
|
animation: viewStateNotifier,
|
||||||
builder: (context, child) {
|
builder: (context, child) {
|
||||||
|
final viewState = viewStateNotifier.value;
|
||||||
return CustomPaint(
|
return CustomPaint(
|
||||||
painter: MinimapPainter(
|
painter: MinimapPainter(
|
||||||
entrySize: entry.displaySize,
|
|
||||||
viewportSize: mqSize,
|
viewportSize: mqSize,
|
||||||
viewCenterOffset: viewStateNotifier.value.position,
|
entrySize: viewState.size ?? entry.displaySize,
|
||||||
viewScale: viewStateNotifier.value.scale,
|
viewCenterOffset: viewState.position,
|
||||||
|
viewScale: viewState.scale,
|
||||||
minimapBorderColor: Colors.white30,
|
minimapBorderColor: Colors.white30,
|
||||||
),
|
),
|
||||||
size: size,
|
size: size,
|
||||||
|
@ -49,8 +50,8 @@ class MinimapPainter extends CustomPainter {
|
||||||
final Color minimapBorderColor, viewportBorderColor;
|
final Color minimapBorderColor, viewportBorderColor;
|
||||||
|
|
||||||
const MinimapPainter({
|
const MinimapPainter({
|
||||||
@required this.entrySize,
|
|
||||||
@required this.viewportSize,
|
@required this.viewportSize,
|
||||||
|
@required this.entrySize,
|
||||||
@required this.viewCenterOffset,
|
@required this.viewCenterOffset,
|
||||||
@required this.viewScale,
|
@required this.viewScale,
|
||||||
this.minimapBorderColor = Colors.white,
|
this.minimapBorderColor = Colors.white,
|
||||||
|
|
|
@ -674,7 +674,7 @@ packages:
|
||||||
description:
|
description:
|
||||||
path: "."
|
path: "."
|
||||||
ref: HEAD
|
ref: HEAD
|
||||||
resolved-ref: "79a3c20ee7f01e6ffb71464000c2ca8f1e28ec44"
|
resolved-ref: aa6400bbc85bf6ce953c4609d126796cdb4ca3c2
|
||||||
url: "git://github.com/deckerst/photo_view.git"
|
url: "git://github.com/deckerst/photo_view.git"
|
||||||
source: git
|
source: git
|
||||||
version: "0.9.2"
|
version: "0.9.2"
|
||||||
|
|
Loading…
Reference in a new issue