From e7016286afa608814be7b2dc1998ae03605ad201 Mon Sep 17 00:00:00 2001 From: bggRGjQaUbCoE Date: Fri, 22 Nov 2024 11:37:55 +0800 Subject: [PATCH] opt: long image view Signed-off-by: bggRGjQaUbCoE --- lib/common/widgets/imageview.dart | 7 +++++-- lib/common/widgets/network_img_layer.dart | 7 ++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/common/widgets/imageview.dart b/lib/common/widgets/imageview.dart index e7909c10..b1a311ac 100644 --- a/lib/common/widgets/imageview.dart +++ b/lib/common/widgets/imageview.dart @@ -16,9 +16,11 @@ class ImageModel { dynamic width; dynamic height; String url; + bool? _isLongPic; dynamic get safeWidth => width ?? 1; dynamic get safeHeight => height ?? 1; + bool get isLongPic => _isLongPic ??= (safeHeight / safeWidth) > (22 / 9); } Widget image( @@ -37,7 +39,7 @@ Widget image( ? maxWidth : (ratioWH >= 1 || (height > width && ratioHW < 1.5)) ? 2 * imageWidth - : imageWidth; + : 1.5 * imageWidth; imageHeight = imageWidth * min(ratioHW, maxRatio); } else if (picArr.length == 2) { imageWidth = imageHeight = 2 * imageWidth; @@ -69,6 +71,7 @@ Widget image( ClipRRect( borderRadius: BorderRadius.circular(12), child: NetworkImgLayer( + isLongPic: picArr[index].isLongPic, src: picArr[index].url, width: imageWidth, height: imageHeight, @@ -76,7 +79,7 @@ Widget image( picArr[index].safeWidth / picArr[index].safeHeight, ), ), - if (picArr[index].safeHeight / picArr[index].safeWidth > 22 / 9) + if (picArr[index].isLongPic) const PBadge( text: '长图', right: 8, diff --git a/lib/common/widgets/network_img_layer.dart b/lib/common/widgets/network_img_layer.dart index d052aec0..7eca48b8 100644 --- a/lib/common/widgets/network_img_layer.dart +++ b/lib/common/widgets/network_img_layer.dart @@ -24,6 +24,7 @@ class NetworkImgLayer extends StatelessWidget { this.ignoreHeight, this.radius, this.imageBuilder, + this.isLongPic = false, }); final String? src; @@ -38,6 +39,7 @@ class NetworkImgLayer extends StatelessWidget { final bool? ignoreHeight; final double? radius; final ImageWidgetBuilder? imageBuilder; + final bool isLongPic; @override Widget build(BuildContext context) { @@ -46,7 +48,9 @@ class NetworkImgLayer extends StatelessWidget { '${src?.startsWith('//') == true ? 'https:$src' : src}@${quality ?? defaultImgQuality}q.webp'; int? memCacheWidth, memCacheHeight; - if (width > height || (origAspectRatio != null && origAspectRatio! > 1)) { + if (isLongPic || + width > height || + (origAspectRatio != null && origAspectRatio! > 1)) { memCacheWidth = width.cacheSize(context); } else if (width < height || (origAspectRatio != null && origAspectRatio! < 1)) { @@ -76,6 +80,7 @@ class NetworkImgLayer extends StatelessWidget { memCacheWidth: memCacheWidth, memCacheHeight: memCacheHeight, fit: BoxFit.cover, + alignment: Alignment.topCenter, fadeOutDuration: fadeOutDuration ?? const Duration(milliseconds: 120), fadeInDuration: