53 lines
1.3 KiB
Dart
53 lines
1.3 KiB
Dart
import 'dart:math';
|
|
import 'package:flutter/material.dart' hide Image;
|
|
|
|
class ImageDetailInfo {
|
|
ImageDetailInfo({
|
|
required this.imageDRect,
|
|
required this.pageSize,
|
|
required this.imageInfo,
|
|
});
|
|
final GlobalKey<State<StatefulWidget>> key = GlobalKey<State>();
|
|
|
|
final Rect imageDRect;
|
|
|
|
final Size pageSize;
|
|
|
|
final ImageInfo imageInfo;
|
|
|
|
double? _maxImageDetailY;
|
|
double get imageBottom => imageDRect.bottom - 20;
|
|
double get maxImageDetailY {
|
|
try {
|
|
//
|
|
return _maxImageDetailY ??= max(
|
|
key.currentContext!.size!.height - (pageSize.height - imageBottom),
|
|
0.1);
|
|
} catch (e) {
|
|
//currentContext is not ready
|
|
return 100.0;
|
|
}
|
|
}
|
|
}
|
|
|
|
double? initScale({
|
|
required Size imageSize,
|
|
required Size size,
|
|
double? initialScale,
|
|
}) {
|
|
final double n1 = imageSize.height / imageSize.width;
|
|
final double n2 = size.height / size.width;
|
|
if (n1 > n2) {
|
|
final FittedSizes fittedSizes =
|
|
applyBoxFit(BoxFit.contain, imageSize, size);
|
|
final Size destinationSize = fittedSizes.destination;
|
|
return size.width / destinationSize.width;
|
|
} else if (n1 / n2 < 1 / 4) {
|
|
final FittedSizes fittedSizes =
|
|
applyBoxFit(BoxFit.contain, imageSize, size);
|
|
final Size destinationSize = fittedSizes.destination;
|
|
return size.height / destinationSize.height;
|
|
}
|
|
|
|
return initialScale;
|
|
}
|