Using Flutter on mobile (iOS and Android), how can I move media to an album?
I tried to combine gallery_saver
and photo_manager
on iOS:
AssetEntity
from Recents
AssetEntity
file under an album with GallerySaver.saveImage
. At this point Recents
showed the same media twice, makes sense.PhotoManager.editor.deleteWithIds
the original AssetEntity
file, and it showed a native popup asking the user if it's ok to delete the media. Bad user experience... Is there a way to change AssetEntity
album, without creating a new file?
Thankfully, the author of the library recently updated it to include album removal feature discussed in this answer. You can see their pull request . Or refer to the method invocation removeAssetsInAlbum
in the README
photo_manager
library is using PHAssetChangeRequest 's method deleteAssets(_:) . You can see this here . This will delete the actual file rather than just remove it from album (more on this in Explanation section)
The solution is to use PHAssetCollectionChangeRequest 's methods. Depends on your use case:
There's a difference between deleting assets and removing assets. Deleting an asset's file is done via PHAssetChangeRequest which deletes the asset file permanently and its references from albums. But removing an asset is done via PHAssetCollectionChangeRequest which removes the asset's reference (not file) from album/s without deleting the file itself. Check this answer .
This section is now obsolete but kept for other use-cases when photo_manager
cannot be used, please refer to the top of this answer if you want to use photo_manager
You have the following options to pick one from that would solve your problem:
photo_manager
, maybe it's there?
Currently photo_manager
uses PHAssetChangeRequest
's method deleteAssets(_:) :
[PHAssetChangeRequest deleteAssets:result];
This should change to using PHAssetCollectionChangeRequest
's method removeAssets(_:) :
[PHAssetCollectionChangeRequest removeAssets:result];
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.