photo_manager 0.4.7

  • Readme
  • Changelog
  • Example
  • Installing
  • 96

photo_manager #

pub package GitHub GitHub stars

A flutter api for photo, you can get image/video from ios or android.

一个提供相册 api 的插件, android ios 可用,没有 ui,以便于自定义自己的界面, 你可以通过提供的 api 来制作图片相关的 ui 或插件

If you just need a picture selector, you can choose to use photo library , a multi image picker. All UI create by flutter.

install #

Add to pubspec #

the latest version is pub package

  photo_manager: $latest_version

import in dart code #

import 'package:photo_manager/photo_manager.dart';

Usage #

request permission #

You must get the user's permission on android/ios.

var result = await PhotoManager.requestPermission();
if (result) {
    // success
} else {
    // fail
    /// if result is fail, you can call `PhotoManager.openSetting();`  to open android/ios applicaton's setting to get permission
List<AssetPathEntity> list = await PhotoManager.getAssetPathList();


List<AssetPathEntity> list = await PhotoManager.getImageAsset();


List<AssetPathEntity> list = await PhotoManager.getVideoAsset();

get asset list from imagePath #

paged #

// page: The page number of the page, starting at 0.
// perPage: The number of pages per page.
final assetList = await path.getAssetListPaged(page, perPage);

The old version, it is not recommended for continued use, because there may be performance issues on some phones. Now the internal implementation of this method is also paged, but the paged count is assetCount of AssetPathEntity.

range #

final assetList = await path.getAssetListRange(start: 0, end: 88); // use start and end to get asset.
// Example: 0~10 will return 10 assets. Special case: If there are only 5, return 5

FilterOption #

The class define in filter_option_page.dart.

Constraint the size, duration.

About needTitle:The title property of AssetEntity is very expensive on iOS. If needTitle is false, AssetEntity.title is empty, default is false. Unless you need this property, please keep it false.

SizeConstraint are valid in both pictures and videos.

DurationConstraint will be ignore with image type.

Old version #

AssetPathEntity data = list[0]; // 1st album in the list, typically the "Recent" or "All" album
List<AssetEntity> imageList = await data.assetList;

AssetEntity #

AssetEntity entity = imageList[0];

File file = await entity.file; // image file

Uint8List originBytes = await entity.originBytes; // image/video original file content,

Uint8List thumbBytes = await entity.thumbData; // thumb data ,you can use Image.memory(thumbBytes); size is 64px*64px;

Uint8List thumbDataWithSize = await entity.thumbDataWithSize(width,height); //Just like thumbnails, you can specify your own size. unit is px; format is optional support jpg and png.

AssetType type = entity.type; // the type of asset enum of other,image,video

Duration duration = entity.videoDuration; //if type is not video, then return null.

Size size = entity.size

int width = entity.width;

int height = entity.height;

DateTime createDt = entity.createDateTime;

DateTime modifiedDt = entity.modifiedDateTime;

/// Gps info of asset. If latitude and longitude is 0, it means that no positioning information was obtained.
/// This information is not necessarily available, because the photo source is not necessarily the camera.
/// Even the camera, due to privacy issues, this property must not be available on androidQ and above.
double latitude = entity.latitude;
double longitude = entiry.longitude;

Latlng latlng = await entity.latlngAsync(); // In androidQ or higher, need use the method to get location info.

location info of android Q #

Because of AndroidQ's privacy policy issues, it is necessary to locate permissions in order to obtain the original image, and to obtain location information by reading the Exif metadata of the data.

Origin description #

The originFile and originBytes will return the original content.

Not guaranteed to be available in flutter.
Because flutter's Image does not support heic.
The video is also the original format, non-exported format, compatibility does not guarantee usability.

observer #

use addChangeCallback to regiser observe.


Experimental #

Delete item #

final List<String> result = await PhotoManager.editor.deleteWithIds([]); // The deleted id will be returned, if it fails, an empty array will be returned.

Tip: You need to call the corresponding PathEntity's refreshPathProperties method to refresh the latest assetCount.

And range way to get the latest data to ensure the accuracy of the current data. Such as example.

Insert new item #

final AssetEntity imageEntity = await PhotoManager.editor.saveImage(uint8list); // nullable

File videoFile = File("video path");
final AssetEntity videoEntity = await await PhotoManager.editor.saveVideo(videoFile); // nullable

iOS plist config #

Because the album is a privacy privilege, you need user permission to access it. You must to modify the Info.plist file in Runner project.

like next

    <string>App need your agree, can visit your album</string>

xcode like image in xcode

In ios11+, if you want to save or delete asset, you also need add NSPhotoLibraryAddUsageDescription to plist.

android config #

about androidX #

Google recommends completing all support-to-AndroidX migrations in 2019. Documentation is also provided.

This library has been migrated in version 0.2.2, but it brings a problem. Sometimes your upstream library has not been migrated yet. At this time, you need to add an option to deal with this problem.

The complete migration method can be consulted gitbook.

Android Q privacy #

Now, the android part of the plugin uses api 29 to compile the plugin, so your android sdk environment must contain api 29 (androidQ).

AndroidQ has a new privacy policy, users can't access the original file.

If your compileSdkVersion and targetSdkVersion are both below 28, you can use PhotoManager.forceOldApi to force the old api to access the album. If you are not sure about this part, don't call this method.

glide #

Android native use glide to create image thumb bytes, version is 4.9.0.

If your other android library use the library, and version is not same, then you need edit your android project's build.gradle.

rootProject.allprojects {

    subprojects {
        project.configurations.all {
            resolutionStrategy.eachDependency { details ->
                if ( == 'com.github.bumptech.glide'
                        &&'glide')) {
                    details.useVersion "4.9.0"

common issues #

ios build error #

if your flutter print like the log. see stackoverflow

Xcode's output:
    The use of Swift 3 @objc inference in Swift 4 mode is deprecated. Please address deprecated @objc inference warnings, test your code with “Use of deprecated Swift 3 @objc inference” logging enabled, and then disable inference by changing the "Swift 3 @objc Inference" build setting to "Default" for the "Runner" target.
    While building module 'photo_manager' imported from /Users/cai/IdeaProjects/flutter/sxw_order/ios/Runner/GeneratedPluginRegistrant.m:9:
    In file included from <module-includes>:1:
    In file included from /Users/cai/IdeaProjects/flutter/sxw_order/build/ios/Debug-iphonesimulator/photo_manager/photo_manager.framework/Headers/photo_manager-umbrella.h:16:
    /Users/cai/IdeaProjects/flutter/sxw_order/build/ios/Debug-iphonesimulator/photo_manager/photo_manager.framework/Headers/MD5Utils.h:5:9: error: include of non-modular header inside framework module 'photo_manager.MD5Utils': '/Applications/' [-Werror,-Wnon-modular-include-in-framework-module]
    #import <CommonCrypto/CommonDigest.h>
    1 error generated.
    /Users/cai/IdeaProjects/flutter/sxw_order/ios/Runner/GeneratedPluginRegistrant.m:9:9: fatal error: could not build module 'photo_manager'
    #import <photo_manager/ImageScannerPlugin.h>
    2 errors generated.


0.4.7 #

New feature:

  • Add FilterOption for method getAssetPathList.

0.4.6 #


  • originFile of AssetEntity


  • location(latitude,longitude) of AssetEntity
  • title of AssetEntity
  • originBytes of AssetEntity
  • param format in thumbDataWithSize of assetEntity.

0.4.5 #


  • Can't get thumb/file of video on androidQ.

0.4.4 #


  • Compatibility code, when the width and height of the video is empty, it can still be scanned.
  • Add a default value to type of getAssetPathList.

0.4.3 #


  • Delete asset.
  • Add Image.
  • Add Video.
  • Add modifiDate property.
  • Fix videoDuration error.


  • CreateDate error.

0.4.2 #

  • Fix ios get full file size error.

0.4.1 #


  • Fix ios build error.

0.4.0 #

Breaking change.

  • Some properties in the entity were modified from asynchronous to synchronous.
  • Remove isCache params. Now, getAssetPathList will reload info everytime. If user want to cache List<AssetPathEntity>, then user must do it self.


  • Added a method getAssetListPaged for paging loading resources to path. The paging implementation is lazy loading, that is, the resource corresponding information is loaded when requested. The entity corresponding to the path is no longer placed in the memory, but is implemented by PHPhoto (ios) and sqlite's limit offset (android).
  • Support AndroidQ privacy.

0.3.5 #


  • ICloud image problem.

0.3.4 #

Support flutter 1.6.0 android's thread changes for channel.

0.3.3 #

Fix customizing album containing folders on iOS.

0.3.2 #

AssetEntity add property: originFile

0.3.1 #

AssetEntity add property: exists

0.3.0 #

  • Support Android X.
  • Breaking change. Migrate from the deprecated original Android Support Library to AndroidX. This shouldn't result in any functional changes, but it requires any Android apps using this plugin to also migrate if they're using the original support library.

fix NPE for image crash on android.

add a method to create AssetEntity with id

add isCache for method getImageAsset,getVideoAsset or getAssetPathList

add observer for photo change.

add field createTime for AssetEntity

0.2.1 #

add two method to load video / image

getVideoAsset getImageAsset

0.2.0 #

add asset size field

release cache method

0.1.10 #


when number of photo/video is 0, will crash

0.1.9 #

add video duration

0.1.8 sort asset by data #

0.1.7 fix bug #

fix bug: Android's latest picture won't be found

update gradle wrapper version.

update kotlin version

0.1.6 #

Fix Android to get pictures that are empty bug.

0.1.5 #

support ios icloud image and video

0.1.4 fix bug #

update all path hasVideo property

0.1.3 add params #

add a params to help user disable get video

0.1.2 fix bug #

ios get video file is async

0.1.1 fix ios video #

fix 'ios video full file is a jpg' problem

0.1.0 support video #

support video in android. and will change api from ImageXXXX to AssetXXXX

0.0.3 fix bug #

update for the issue #1 (NPE when request other permission on android)

0.0.2 update readme #

0.0.1 #

first version

api for photo


image_scanner_example #

Demonstrates how to use the image_scanner plugin.

Getting Started #

For help getting started with Flutter, view our online documentation.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  photo_manager: ^0.4.7

2. Install it

You can install packages from the command line:

with Flutter:

$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:photo_manager/photo_manager.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Jan 21, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.4
  • Flutter: 1.12.13+hotfix.5

Health suggestions

Format lib/src/factory.dart.

Run flutter format to format lib/src/factory.dart.

Format lib/src/filter/filter_options.dart.

Run flutter format to format lib/src/filter/filter_options.dart.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.28.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8