From 7569b4260e4c3319510810da81e176fd345dc3d3 Mon Sep 17 00:00:00 2001 From: Neeraj Gupta Date: Wed, 4 Aug 2021 19:15:34 +0530 Subject: [PATCH] Identify livePhoto based on subTypes --- lib/models/file.dart | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/lib/models/file.dart b/lib/models/file.dart index 88728b647..af20a0c7a 100644 --- a/lib/models/file.dart +++ b/lib/models/file.dart @@ -1,3 +1,4 @@ + import 'package:flutter/foundation.dart'; import 'package:path/path.dart'; import 'package:photo_manager/photo_manager.dart'; @@ -33,17 +34,7 @@ class File { file.title = asset.title; file.deviceFolder = pathName; file.location = Location(asset.latitude, asset.longitude); - switch (asset.type) { - case AssetType.image: - file.fileType = FileType.image; - break; - case AssetType.video: - file.fileType = FileType.video; - break; - default: - file.fileType = FileType.other; - break; - } + file.fileType = _fileTypeFromAsset(asset); file.creationTime = asset.createDateTime.microsecondsSinceEpoch; if (file.creationTime == 0) { try { @@ -61,6 +52,29 @@ class File { return file; } + static FileType _fileTypeFromAsset(AssetEntity asset) { + FileType type = FileType.image; + switch (asset.type) { + case AssetType.image: + type = FileType.image; + // PHAssetMediaSubtype.photoLive.rawValue is 8 + // This hack should go away once photos_manager support livePhotos + if (asset.subTypes != null && + asset.subTypes > -1 && + (asset.subTypes & 8) != 0) { + type = FileType.livePhoto; + } + break; + case AssetType.video: + type = FileType.video; + break; + default: + type = FileType.other; + break; + } + return type; + } + Future getAsset() { if (localID == null) { return Future.value(null); @@ -149,7 +163,7 @@ class File { @override String toString() { - return '''File(uploadedFileId: $uploadedFileID, ownerID: $ownerID, + return '''File(uploadedFileId: $uploadedFileID, ownerID: $ownerID, collectionID: $collectionID, updationTime: $updationTime)'''; }