From 59915852bce28469cadc381997daf5eee3624b5a Mon Sep 17 00:00:00 2001 From: "Michael W. Aziz" Date: Fri, 12 Sep 2025 19:08:01 -0400 Subject: [PATCH] [FEAT] working on the image widget for dynamic memory management and caching. --- lib/src/Widgets/src/image.widget.dart | 32 ++++++++++++++++++--------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/lib/src/Widgets/src/image.widget.dart b/lib/src/Widgets/src/image.widget.dart index d49b87b..4790a40 100644 --- a/lib/src/Widgets/src/image.widget.dart +++ b/lib/src/Widgets/src/image.widget.dart @@ -76,7 +76,7 @@ class AstromicImage extends StatelessWidget { this.blendMode, this.fadeInCurve, this.fadeInDuration, - this.imageQuality = 0.35, + this.imageQuality = 0.5, // this.svgColor, // @@ -291,14 +291,19 @@ class AstromicImage extends StatelessWidget { } } - - // Build image provider and ensure it's resized to (or near) the rendering size. - ImageProvider _imageProvider(_DeclaredAssetType type, dynamic ref, Size size, double imageQuality) { +// Build image provider and ensure it's resized to (or near) the rendering size. + ImageProvider _imageProvider( + _DeclaredAssetType type, + dynamic ref, + Size size, + double imageQuality, + ) { // imageQuality is used as a downscale factor: 1.0 -> full target resolution, 0.5 -> half resolution final double factor = imageQuality.clamp(0.1, 1.0); + // If size is infinite for a dimension, we skip resize for that dim (pass 0) - final int? targetWidth = size.width.isFinite ? (size.width * factor).clamp(1, 10000).toInt() : null; - final int? targetHeight = size.height.isFinite ? (size.height * factor).clamp(1, 10000).toInt() : null; + final int? targetWidth = size.width.isFinite ? (size.width * factor).clamp(1, 4096).toInt() : null; + final int? targetHeight = size.height.isFinite ? (size.height * factor).clamp(1, 4096).toInt() : null; ImageProvider baseProvider; switch (type) { @@ -309,17 +314,22 @@ class AstromicImage extends StatelessWidget { baseProvider = MemoryImage(ref as Uint8List); break; case _DeclaredAssetType.path: - baseProvider = AssetImage(ref as String); - break; case _DeclaredAssetType.fallback: baseProvider = AssetImage(ref as String); break; } - // If both target dims are null (infinite), return base provider (no resize). - if (targetWidth == null && targetHeight == null) return baseProvider; + // ✅ Skip resizing for AssetImage (Flutter handles resolution variants) + if (baseProvider is AssetImage) { + return baseProvider; + } - // If one of them is null, supply 0 for that dim to ResizeImage (it will only respect non-zero dim). + // If both target dims are null (infinite), return base provider (no resize). + if (targetWidth == null && targetHeight == null) { + return baseProvider; + } + + // If one of them is null, supply 0 for that dim (ResizeImage respects non-zero dim). final int w = targetWidth ?? 0; final int h = targetHeight ?? 0;