[FEAT] working on the image widget for dynamic memory management and caching.
This commit is contained in:
@@ -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) {
|
||||
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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user