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

View File

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