diff --git a/mobile/lib/entities/asset.entity.dart b/mobile/lib/entities/asset.entity.dart index 370dd83cdf..17f107f3cf 100644 --- a/mobile/lib/entities/asset.entity.dart +++ b/mobile/lib/entities/asset.entity.dart @@ -174,33 +174,17 @@ class Asset { int stackCount; - /// Aspect ratio of the asset /// Returns null if the asset has no sync access to the exif info @ignore double? get aspectRatio { - late final double? orientatedWidth; - late final double? orientatedHeight; - - if (exifInfo != null) { - orientatedWidth = this.orientatedWidth?.toDouble(); - orientatedHeight = this.orientatedHeight?.toDouble(); - } else if (didUpdateLocal) { - final currentLocal = local; - if (currentLocal == null) { - throw Exception('Asset $fileName has no local data'); - } - orientatedWidth = currentLocal.orientatedWidth.toDouble(); - orientatedHeight = currentLocal.orientatedHeight.toDouble(); - } else { - orientatedWidth = null; - orientatedHeight = null; - } + final orientatedWidth = this.orientatedWidth; + final orientatedHeight = this.orientatedHeight; if (orientatedWidth != null && orientatedHeight != null && orientatedWidth > 0 && orientatedHeight > 0) { - return orientatedWidth / orientatedHeight; + return orientatedWidth.toDouble() / orientatedHeight.toDouble(); } return null; @@ -249,13 +233,49 @@ class Asset { @ignore set byteHash(List hash) => checksum = base64.encode(hash); + /// Returns null if the asset has no sync access to the exif info @ignore - int? get orientatedWidth => - exifInfo != null && exifInfo!.isFlipped ? height : width; + @pragma('vm:prefer-inline') + bool? get isFlipped { + final exifInfo = this.exifInfo; + if (exifInfo != null) { + return exifInfo.isFlipped; + } + if (didUpdateLocal) { + final local = this.local; + if (local == null) { + throw Exception('Asset $fileName has no local data'); + } + return local.orientation == 90 || local.orientation == 270; + } + + return null; + } + + /// Returns null if the asset has no sync access to the exif info @ignore - int? get orientatedHeight => - exifInfo != null && exifInfo!.isFlipped ? width : height; + @pragma('vm:prefer-inline') + int? get orientatedHeight { + final isFlipped = this.isFlipped; + if (isFlipped == null) { + return null; + } + + return isFlipped ? width : height; + } + + /// Returns null if the asset has no sync access to the exif info + @ignore + @pragma('vm:prefer-inline') + int? get orientatedWidth { + final isFlipped = this.isFlipped; + if (isFlipped == null) { + return null; + } + + return isFlipped ? height : width; + } @override bool operator ==(other) { diff --git a/mobile/lib/entities/exif_info.entity.dart b/mobile/lib/entities/exif_info.entity.dart index 7a0db3fdeb..c46f3dddc1 100644 --- a/mobile/lib/entities/exif_info.entity.dart +++ b/mobile/lib/entities/exif_info.entity.dart @@ -50,6 +50,7 @@ class ExifInfo { bool? _isFlipped; @ignore + @pragma('vm:prefer-inline') bool get isFlipped => _isFlipped ??= _isOrientationFlipped(orientation); @ignore diff --git a/mobile/lib/widgets/asset_viewer/detail_panel/file_info.dart b/mobile/lib/widgets/asset_viewer/detail_panel/file_info.dart index b2a0107546..0dd3305302 100644 --- a/mobile/lib/widgets/asset_viewer/detail_panel/file_info.dart +++ b/mobile/lib/widgets/asset_viewer/detail_panel/file_info.dart @@ -15,10 +15,10 @@ class FileInfo extends StatelessWidget { Widget build(BuildContext context) { final textColor = context.isDarkTheme ? Colors.white : Colors.black; + final height = asset.orientatedHeight ?? asset.height; + final width = asset.orientatedWidth ?? asset.width; String resolution = - asset.orientatedHeight != null && asset.orientatedWidth != null - ? "${asset.orientatedHeight} x ${asset.orientatedWidth} " - : ""; + height != null && width != null ? "$height x $width " : ""; String fileSize = asset.exifInfo?.fileSize != null ? formatBytes(asset.exifInfo!.fileSize!) : "";