photos_native 0.0.7 copy "photos_native: ^0.0.7" to clipboard
photos_native: ^0.0.7 copied to clipboard

High performance Flutter plugin for photos library. It can load photo albums, load image/thumnail, save, share...

photos_native #

A Flutter native plugin for photo library.

1. Getting Started #

photos_native is high performance, yet easy to use photo library plugin, working on Android and iOS. It can load albums, load image/thumnail, save, share... photo images.

iOS Android
ios android

Install #

  1. With Flutter:

    $ flutter pub add photos_native
    
  2. YAML

    dependencies:
      photos_native: ^0.0.1
    

Working with library #

Set up your project #

This library depends on flutter-permission-handler, so you need to set up correct permission before using. While the permissions are being requested during runtime, you'll still need to tell the OS which permissions your app might potentially use. That requires adding permission configuration to Android- and iOS-specific files.

Android

You don't need to setup anything if you target SDK 30 or above.

If your compileSdkVersion/targetSdkVersion is 29, you can consider adding android:requestLegacyExternalStorage="true" to your AndroidManifest.xml in order to obtain resources:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.your_package">

    <application android:label="{appName}"
        android:icon="@mipmap/ic_launcher"
        android:requestLegacyExternalStorage="true">
    </application>
</manifest>
iOS 1. Add the following to your `Podfile` file:
post_install do |installer|
    installer.pods_project.targets.each do |target|
    ... # Here are some configurations automatically generated by flutter

    # Start of the permission_handler configuration
    target.build_configurations.each do |config|
        config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [
        '$(inherited)',

        ## dart: PermissionGroup.photos
        'PERMISSION_PHOTOS=1',
        ]

    end 
    # End of the permission_handler configuration
    end
end
  1. Config plist file Add key NSPhotoLibraryUsageDescription to the the ios/Runner/Info.plist:
<key>NSPhotoLibraryUsageDescription</key>
<string>App needs access to photo library</string>

Usage #

Basic Concepts #

PHItem is a photo item on device, PHItem has an photo ID exclusively or file URI.

PHAlbum is abstract version of MediaStore bucket on Android, or PHAssetCollection on iOS. PHAlbum can contains multiple PHItems.

PHGallery contains all photo albums on the device.

Default album is All Photos which contains all photos in gallery (user can select any name to default albums)

PHImageDescriptor is a image descriptor, PHImageDescriptor contain pixel bytes, width and height of the image.

Request permission #

Request permission for photo library

await PhotosNative.requestPermissions();
final gallery = await PhotosNative.loadGallery(title: 'All Photos');

See PHGallery for more details

Get thumbnail image descriptor #

Return thumbnail image descriptor

final descriptor = await PhotosNative.getThumbnail(200, 200, 'id');

// or load from uri

final descriptor = await PhotosNative.getThumbnail(200, 200, 'image uri');

See class PHImageDescriptor for more details

Get image descriptor #

Return image descriptor of a photo

final descriptor = await PhotosNative.getPixels('photo_id');

See class PHImageDescriptor for more details

Delete images #

Return the number of deleted images

await PhotosNative.delete(['photo_id', 'photo_id2']);

Save image #

Save image to a path/directory ...

await PhotosNative.save(bytes, width, height, path: path);

Share image #

Share image with other apps

await PhotosNative.share(bytes, width, height);

Experiment #

Working with Flutter backend texture. Read Flutter Texture for more details. You can experiment these features to check if it can improve your app performance.

Load image texture #

int textureId = await PhotosNative.acquireTexture(id, width, height);

// usage
Container(child: Texture(textureId: textureId));

Release image texture #

await PhotosNative.releaseTexture(id);

Author #

This photo plugin for Flutter is developed by Annotium 👈. Contact us at email

3
likes
130
points
1
downloads

Publisher

unverified uploader

Weekly Downloads

High performance Flutter plugin for photos library. It can load photo albums, load image/thumnail, save, share...

Homepage

Documentation

API reference

License

MIT (license)

Dependencies

crypto, equatable, flutter, permission_handler, plugin_platform_interface

More

Packages that depend on photos_native

Packages that implement photos_native