mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
opt: image view
Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
@@ -71,12 +71,12 @@ Widget image(
|
|||||||
ClipRRect(
|
ClipRRect(
|
||||||
borderRadius: BorderRadius.circular(12),
|
borderRadius: BorderRadius.circular(12),
|
||||||
child: NetworkImgLayer(
|
child: NetworkImgLayer(
|
||||||
isLongPic: picArr[index].isLongPic,
|
|
||||||
src: picArr[index].url,
|
src: picArr[index].url,
|
||||||
width: imageWidth,
|
width: imageWidth,
|
||||||
height: imageHeight,
|
height: imageHeight,
|
||||||
origAspectRatio:
|
isLongPic: () => picArr[index].isLongPic,
|
||||||
picArr[index].safeWidth / picArr[index].safeHeight,
|
callback: () =>
|
||||||
|
picArr[index].safeWidth <= picArr[index].safeHeight,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
if (picArr[index].isLongPic)
|
if (picArr[index].isLongPic)
|
||||||
|
|||||||
@@ -19,12 +19,12 @@ class NetworkImgLayer extends StatelessWidget {
|
|||||||
this.fadeInDuration,
|
this.fadeInDuration,
|
||||||
// 图片质量 默认1%
|
// 图片质量 默认1%
|
||||||
this.quality,
|
this.quality,
|
||||||
this.origAspectRatio,
|
|
||||||
this.semanticsLabel,
|
this.semanticsLabel,
|
||||||
this.ignoreHeight,
|
this.ignoreHeight,
|
||||||
this.radius,
|
this.radius,
|
||||||
this.imageBuilder,
|
this.imageBuilder,
|
||||||
this.isLongPic = false,
|
this.isLongPic,
|
||||||
|
this.callback,
|
||||||
});
|
});
|
||||||
|
|
||||||
final String? src;
|
final String? src;
|
||||||
@@ -34,31 +34,24 @@ class NetworkImgLayer extends StatelessWidget {
|
|||||||
final Duration? fadeOutDuration;
|
final Duration? fadeOutDuration;
|
||||||
final Duration? fadeInDuration;
|
final Duration? fadeInDuration;
|
||||||
final int? quality;
|
final int? quality;
|
||||||
final double? origAspectRatio;
|
|
||||||
final String? semanticsLabel;
|
final String? semanticsLabel;
|
||||||
final bool? ignoreHeight;
|
final bool? ignoreHeight;
|
||||||
final double? radius;
|
final double? radius;
|
||||||
final ImageWidgetBuilder? imageBuilder;
|
final ImageWidgetBuilder? imageBuilder;
|
||||||
final bool isLongPic;
|
final Function? isLongPic;
|
||||||
|
final Function? callback;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final int defaultImgQuality = GlobalData().imgQuality;
|
late final int defaultImgQuality = GlobalData().imgQuality;
|
||||||
final String imageUrl =
|
final String imageUrl =
|
||||||
'${src?.startsWith('//') == true ? 'https:$src' : src}@${quality ?? defaultImgQuality}q.webp';
|
'${src?.startsWith('//') == true ? 'https:$src' : src}@${quality ?? defaultImgQuality}q.webp';
|
||||||
int? memCacheWidth, memCacheHeight;
|
int? memCacheWidth, memCacheHeight;
|
||||||
|
|
||||||
if (isLongPic ||
|
if (callback?.call() == true || width <= height) {
|
||||||
width > height ||
|
|
||||||
(origAspectRatio != null && origAspectRatio! > 1)) {
|
|
||||||
memCacheWidth = width.cacheSize(context);
|
memCacheWidth = width.cacheSize(context);
|
||||||
} else if (width < height ||
|
|
||||||
(origAspectRatio != null && origAspectRatio! < 1)) {
|
|
||||||
memCacheHeight = height.cacheSize(context);
|
|
||||||
} else {
|
} else {
|
||||||
// 不能同时设置,否则会导致图片变形
|
memCacheHeight = height.cacheSize(context);
|
||||||
memCacheWidth = width.cacheSize(context);
|
|
||||||
// memCacheHeight = height.cacheSize(context);
|
|
||||||
}
|
}
|
||||||
Widget res = src != '' && src != null
|
Widget res = src != '' && src != null
|
||||||
? ClipRRect(
|
? ClipRRect(
|
||||||
@@ -80,7 +73,9 @@ class NetworkImgLayer extends StatelessWidget {
|
|||||||
memCacheWidth: memCacheWidth,
|
memCacheWidth: memCacheWidth,
|
||||||
memCacheHeight: memCacheHeight,
|
memCacheHeight: memCacheHeight,
|
||||||
fit: BoxFit.cover,
|
fit: BoxFit.cover,
|
||||||
alignment: Alignment.topCenter,
|
alignment: isLongPic?.call() == true
|
||||||
|
? Alignment.topCenter
|
||||||
|
: Alignment.center,
|
||||||
fadeOutDuration:
|
fadeOutDuration:
|
||||||
fadeOutDuration ?? const Duration(milliseconds: 120),
|
fadeOutDuration ?? const Duration(milliseconds: 120),
|
||||||
fadeInDuration:
|
fadeInDuration:
|
||||||
@@ -126,7 +121,7 @@ class NetworkImgLayer extends StatelessWidget {
|
|||||||
width: width,
|
width: width,
|
||||||
height: height,
|
height: height,
|
||||||
cacheWidth: width.cacheSize(context),
|
cacheWidth: width.cacheSize(context),
|
||||||
cacheHeight: height.cacheSize(context),
|
// cacheHeight: height.cacheSize(context),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user