From 3a17837cc64d17e52d04e6f6ab72687ba973e3d1 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sun, 7 Sep 2025 14:12:51 +0800 Subject: [PATCH] :lipstick: Optimize cloud file rendering --- .../content/cloud_file_collection.dart | 10 +++- lib/widgets/content/image.dart | 54 +++++++++---------- 2 files changed, 33 insertions(+), 31 deletions(-) diff --git a/lib/widgets/content/cloud_file_collection.dart b/lib/widgets/content/cloud_file_collection.dart index 929488c5..cef2e245 100644 --- a/lib/widgets/content/cloud_file_collection.dart +++ b/lib/widgets/content/cloud_file_collection.dart @@ -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()); diff --git a/lib/widgets/content/image.dart b/lib/widgets/content/image.dart index bf17fb39..55e3a1b7 100644 --- a/lib/widgets/content/image.dart +++ b/lib/widgets/content/image.dart @@ -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'), + ); + }, + ), + ], ); } }