How to get single AssetEntity from given path using photo_manager

819 views Asked by At

i am using photo_manager package for handling with galley media

the following method is for fetch media

first getting the available albums

final  albums = await PhotoManager.getAssetPathList(onlyAll: true, type:RequestType.common);

second fetch media from given album index

final media = await albums[0].getAssetListPaged( page: pageIntIncreaseMap[fedback]!, size:50,)

now using for/loop to get per file features

for (var asset in media ) {
// action
} 

now my question what if i want to get single AssetEntity by given path without to go through the last methods ..

i found the following method in plugin doc

final AssetEntity? asset = await AssetEntity.fromId('430');

this is work fine but i need to get AssetEntity using the path and not id ..

Any suggestions ?

1

There are 1 answers

0
raw-chicken On

See the github here. It's recommended to do it as so:

// Save an existed image to an entity from it's path.
final AssetEntity? imageEntityWithPath = await PhotoManager.editor.saveImageWithPath(
  path, // Use the absolute path of your source file, it's more like a copy method.
  title: 'same_as_above.jpg',
);