From 3bff0c88e77a0c4f5c57efefacc5045ea336f4e6 Mon Sep 17 00:00:00 2001 From: orz12 Date: Thu, 25 Jan 2024 12:43:48 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=AF=84=E8=AE=BA=E5=8C=BA=E5=9B=BE?= =?UTF-8?q?=E7=89=87=E6=8B=89=E4=BC=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/common/widgets/network_img_layer.dart | 31 +++++++---------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/lib/common/widgets/network_img_layer.dart b/lib/common/widgets/network_img_layer.dart index 03adc166e..7ea20af96 100644 --- a/lib/common/widgets/network_img_layer.dart +++ b/lib/common/widgets/network_img_layer.dart @@ -35,29 +35,16 @@ class NetworkImgLayer extends StatelessWidget { final String imageUrl = '${src!.startsWith('//') ? 'https:${src!}' : src!}@${quality ?? 100}q.webp'; int? memCacheWidth, memCacheHeight; - double aspectRatio = (width / height).toDouble(); - void setMemCacheSizes() { - if (aspectRatio > 1) { - memCacheHeight = height.cacheSize(context); - } else if (aspectRatio < 1) { - memCacheWidth = width.cacheSize(context); - } else { - if (origAspectRatio != null && origAspectRatio! > 1) { - memCacheWidth = width.cacheSize(context); - } else if (origAspectRatio != null && origAspectRatio! < 1) { - memCacheHeight = height.cacheSize(context); - } else { - memCacheWidth = width.cacheSize(context); - memCacheHeight = height.cacheSize(context); - } - } - } - - setMemCacheSizes(); - - if (memCacheWidth == null && memCacheHeight == null) { - memCacheWidth = width.toInt(); + if (width > height || (origAspectRatio != null && origAspectRatio! > 1)) { + memCacheWidth = width.cacheSize(context); + } else if (width < height || + (origAspectRatio != null && origAspectRatio! < 1)) { + memCacheHeight = height.cacheSize(context); + } else { + // 不能同时设置,否则会导致图片变形 + memCacheWidth = width.cacheSize(context); + // memCacheHeight = height.cacheSize(context); } return src != '' && src != null