local_image_provider 1.0.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 87

Local Image Provider Plugin #

pub package build status

A library for searching and retrieving the metadata and contents of the images and albums on a mobile device.

This plugin contains a set of classes that make it easy to discover the metadata of the images and albums on the mobile device. It supports both Android and iOS. The content of images can be retrieved in a format compatible with ImageProvider. Note that this plugin has no UI components, it provides information about local photos that can be used to develop other applications.

Recent Updates #

The 0.9.0 version improves support for album types on iOS.

The 0.8.0 version upgrades to Flutter 1.12.13. This version may not be backwards compatible due to a change in the ImageProvider.

Note: If you have feature requests or issue reports please post them as issues.

Using #

To retrieve the list of the ten latest local images import the package and call the plugin, like so:

import 'package:local_image_provider/local_image_provider.dart' as lip;

    lip.LocalImageProvider imageProvider = lip.LocalImageProvider();
    bool hasPermission = await imageProvider.initialize();
    if ( hasPermission) {
        List<lip.LocalImage> images = await imageProvider.findLatest(10);
        images.forEach((image) => print( image.id));
    else {
        print("The user has denied access to images on their device.");

Get an ImageProvider for a local image like so:

import 'package:local_image_provider/local_image_provider.dart' as lip;
import 'package:flutter/painting.dart';
// ...

    lip.LocalImageProvider imageProvider = lip.LocalImageProvider();
    bool hasPermission = await imageProvider.initialize();
    if ( hasPermission) {
        List<lip.LocalImage> images = await imageProvider.findLatest(1);
        if ( !images.isEmpty ) {
            lip.LocalImage image = images.first;
            DeviceImage deviceImg = DeviceImage( image );
        else {
            print("No images found on the device.");
    else {
        print("The user has denied access to images on their device.");

The DeviceImage can be used directly as an ImageProvider in an Image widget in Flutter. Assuming that _selectedImg is a LocalImage then that image can be displayed in a Flutter Widget tree like so:

        child: Image( image: DeviceImage( _selectedImg ),

Permissions #

Applications using this plugin require the following user permissions.

iOS #

Add the following key to your Info.plist file, located in <project root>/ios/Runner/Info.plist:

  • NSPhotoLibraryUsageDescription - describe why your app needs permission for the photo library. This is called Privacy - Photo Library Usage Description in the visual editor. This permission is required for the app to read the image and album information.

Android #

Add the storage permission to your AndroidManifest.xml file, located in <project root>/android/app/src/main/AndroidManifest.xml:

  • android.permission.READ_EXTERNAL_STORAGE - this allows the app to query and read the image and album information.

Build Issues #

If you get the error "File local_image_provider-Swift.h missing" when trying to build, see this SO reference for possible solutions. The issue seems to be mixing Swift plugins with Flutter projects that weren't built with the Swift option. At least one user resolved the issue by adding use_frameworks! to their Podfile. That looks like this:

target 'Runner' do

Changelog #

1.0.0 #

Updates #

  • fix for file not found exception in imageBytes
  • DeviceImage now loads a default image if the load fails

0.9.0 #

New #

  • Added albumType to LocalAlbum provides more detail on the album type for iOS, always album for Android
  • New options added for LocalAlbumType
  • FindAlbum now restricts by the requested LocalAlbumType

Breaking #

  • coverImgId on LocalAlbum which was deprecated is now gone, use coverImg instead

0.8.2 #

Breaking #

  • Upgrade to Swift 5 to match Flutter 1.12. Projects including this plugin must be using Swift 5.

0.8.1 #

Updates #

  • Upgrade Kotlin to 1.3.5 to match the Flutter 1.12 version
  • Upgrade Gradle build to 3.5.0 to match the Flutter 1.12 version

0.8.0 #

Updates #

  • updated for Flutter 1.12.x, fix for DeviceImage, likely won't work for earlier Flutter versions

0.7.5 #

Updates #

  • findImagesInAlbum was returning non image assets like video, this is fixed now, only images are returned
  • the count member of LocalAlbum didn't match the count of images returned by findImagesInAlbum, this is fixed by the change above.

0.7.4 #

Updates #

  • initialize could return true and still fail to load the first few images, now ensures all init is done before returning

0.7.3 #

Updates #

  • fix for break in iOS implementation in 0.7.2

0.7.2 #

Updates #

  • fix for prompt for user photo permission before initialize on iOS 10/11

0.7.1 #

New #

  • LocalImage hasPermission added

Updates #

  • fix for permission handling to ensure it doesn't conflict with other permission requests

0.7.0 #

Breaking #

  • LocalAlbum.coverImgId has been deprecated
  • reordered height, width parameters on LocalImage constructor to match imageBytes method
  • LocalImage.getImageBytes now takes a LocalImageProvider as a parameter to improve testability
  • LocalAlbum.getCoverImage now takes a LocalImageProvider as a parameter to improve testability

New #

  • LocalAlbum.coverImg has been added
  • LocalAlbum.imageCount property
  • DeviceImage has been added, use instead of using the getImageBytes method directly
  • LocalImage constructor is now const
  • LocalAlbum constructor is now const
  • added == and hashCode for both LocalImage and LocalAlbum, note they depend only on the id
  • LocalImageProvder stats added for image loading, see resetStats(), imgBytesLoaded, lastLoadTime, totalLoadTime

0.6.0 #

Breaking #

  • renamed getLatest -> findLatest
  • renamed getAlbums -> findAlbums

New #

  • findImagesInAlbum to list all the images contained in a particular album

0.5.2 #

Breaking #

  • Added initialize method, now required before using the plugin
  • Methods are no longer static, you must now create an instance and use that

Updates #

  • Added permission checking to both iOS and Android

0.5.1 #

  • Fixes issues pointed out by pub_dev analysis
  • updated description in pubspec
  • updated json_annotation dependency to 3.0
  • ran format on dart files

0.5.0 #

  • Initial release with limited functionality, supports only:
    • getting album descriptions
    • getting latest image descriptions
    • getting bytes for image.
  • Android and iOS 10+ support


import 'package:flutter/material.dart';
import 'package:local_image_provider_example/local_image_body_widget.dart';

void main() => runApp(ExampleApp());

/// A simple application that shows the functionality of the
/// local_image_provider plugin.
/// See [LocalImageBodyWidget] for the main part of the
/// example app.
class ExampleApp extends StatelessWidget {
  Widget build(BuildContext context) {
    return MaterialApp(
      home: LocalImageBodyWidget(),

Use this package as a library

1. Depend on it

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

  local_image_provider: ^1.0.0

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:local_image_provider/local_image_provider.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 Mar 31, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6
  • Flutter: 1.12.13+hotfix.8

Health suggestions

Fix lib/device_image.dart. (-0.50 points)

Analysis of lib/device_image.dart reported 1 hint:

line 83 col 35: The exception variable 'err' isn't used, so the 'catch' clause can be removed.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
json_annotation ^3.0.1 3.0.1
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
Dev dependencies
build_runner ^1.8.0
json_serializable ^3.2.5