💄 Optimize cloud file rendering

This commit is contained in:
2025-09-07 14:12:51 +08:00
parent 2617a64acf
commit 3a17837cc6
2 changed files with 33 additions and 31 deletions

View File

@@ -812,11 +812,16 @@ class _CloudFileListEntry extends HookConsumerWidget {
final lockedByDS = dataSaving && !showDataSaving.value;
final lockedByMature = file.sensitiveMarks.isNotEmpty && !showMature.value;
final meta = file.fileMeta is Map ? file.fileMeta as Map : const {};
final hasRatio =
meta.containsKey('ratio') &&
(meta['ratio'] is num && (meta['ratio'] as num) != 0);
final ratio =
(meta['ratio'] is num && (meta['ratio'] as num) != 0)
? (meta['ratio'] as num).toDouble()
: 1.0;
final fit = hasRatio ? BoxFit.cover : BoxFit.contain;
Widget bg = const SizedBox.shrink();
if (isImage) {
if (meta['blur'] is String) {
@@ -825,6 +830,7 @@ class _CloudFileListEntry extends HookConsumerWidget {
bg = ImageFiltered(
imageFilter: ImageFilter.blur(sigmaX: 10, sigmaY: 10),
child: CloudFileWidget(
fit: fit,
item: file,
noBlurhash: true,
useInternalGate: false,
@@ -843,13 +849,13 @@ class _CloudFileListEntry extends HookConsumerWidget {
item: file,
heroTag: heroTag,
noBlurhash: true,
fit: BoxFit.contain,
fit: fit,
useInternalGate: false,
)
: CloudFileWidget(
item: file,
heroTag: heroTag,
fit: BoxFit.contain,
fit: fit,
useInternalGate: false,
))
: AspectRatio(aspectRatio: ratio, child: const SizedBox.shrink());

View File

@@ -31,35 +31,31 @@ class UniversalImage extends StatelessWidget {
height != null ? (height! * devicePixelRatio).round() : null;
}
return SizedBox(
width: width,
height: height,
child: Stack(
fit: StackFit.expand,
children: [
if (blurHash != null) BlurHash(hash: blurHash!),
CachedNetworkImage(
imageUrl: uri,
fit: fit,
width: width,
height: height,
memCacheHeight: cacheHeight,
memCacheWidth: cacheWidth,
progressIndicatorBuilder: (context, url, progress) {
return Center(
child: CircularProgressIndicator(value: progress.progress),
);
},
errorWidget: (context, url, error) {
return Image.asset(
'assets/images/media-offline.jpg',
fit: BoxFit.cover,
key: Key('image-broke-$uri'),
);
},
),
],
),
return Stack(
fit: StackFit.expand,
children: [
if (blurHash != null) BlurHash(hash: blurHash!),
CachedNetworkImage(
imageUrl: uri,
fit: fit,
width: width,
height: height,
memCacheHeight: cacheHeight,
memCacheWidth: cacheWidth,
progressIndicatorBuilder: (context, url, progress) {
return Center(
child: CircularProgressIndicator(value: progress.progress),
);
},
errorWidget: (context, url, error) {
return Image.asset(
'assets/images/media-offline.jpg',
fit: BoxFit.cover,
key: Key('image-broke-$uri'),
);
},
),
],
);
}
}