A Flutter plugin that lists native gallery items.

Overview

Media Gallery plugin for Flutter

pub package

A Flutter plugin that lists native gallery items.

Installation

First, add media_gallery as a dependency in your pubspec.yaml file.

iOS

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

<key>NSPhotoLibraryUsageDescription</key>
<string>Example usage description</string>

Android

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

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

You should also manage those permissions (for example thanks to the permission_handler plugin). You can see an example for more details.

Usage

Listing media collections

final List<MediaCollection> collections = await MediaGallery.listMediaCollections(
    mediaTypes: [MediaType.image, MediaType.video],
);

Listing medias in a collection

final MediaPage imagePage = await collection.getMedias(
    mediaType: MediaType.image,
    take: 500,
);
final MediaPage videoPage = await collection.getMedias(
    mediaType: MediaType.video,
    take: 500,
);
final List<Media> allMedias = [
    ...imageRange.items,
    ...videoRange.items,
]
..sort((x, y) => y.creationDate.compareTo(x.creationDate));

Loading more medias in a collection

if (!imagePage.isLast) {
    final nextImagePage = await imagePage.nextPage();
    // ...
}

Getting a file

final File file = await media.getFile();

Getting thumbnail data

final List<int> data = await media.getThumbnail();

Displaying thumbnails

MediaThumbnailProvider, MediaCollectionThumbnailProvider are available to display thumbnail images (here with the help of transparent_image) :

FadeInImage(
    fit: BoxFit.cover,
    placeholder: MemoryImage(kTransparentImage),
    image: MediaThumbnailProvider(
        media: media,
    ),
)

Displaying medias

You can use MediaImageProvider to display an image (here with the help of transparent_image):

FadeInImage(
    fit: BoxFit.cover,
    placeholder: MemoryImage(kTransparentImage),
    image: MediaImageProvider(
        media: media,
    ),
)

To display a video, you can use video_player.

Image/Video picker

picker

You can build a gallery picker easily with this package.

See the example for more details.

Comments
  • App Crash on Android Device (Emulator Android 10 Api 29, Google Pixel API 29)

    App Crash on Android Device (Emulator Android 10 Api 29, Google Pixel API 29)

    Hey whenever I try to get the Medias from my phones the app crashes with following stack trace:

    E/AndroidRuntime(25416): FATAL EXCEPTION: AsyncTask #1
    E/AndroidRuntime(25416): Process: com.app.dayblizz, PID: 25416
    E/AndroidRuntime(25416): java.lang.RuntimeException: An error occurred while executing doInBackground()
    E/AndroidRuntime(25416): 	at android.os.AsyncTask$4.done(AsyncTask.java:399)
    E/AndroidRuntime(25416): 	at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
    E/AndroidRuntime(25416): 	at java.util.concurrent.FutureTask.setException(FutureTask.java:252)
    E/AndroidRuntime(25416): 	at java.util.concurrent.FutureTask.run(FutureTask.java:271)
    E/AndroidRuntime(25416): 	at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:289)
    E/AndroidRuntime(25416): 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
    E/AndroidRuntime(25416): 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
    E/AndroidRuntime(25416): 	at java.lang.Thread.run(Thread.java:919)
    E/AndroidRuntime(25416): Caused by: java.lang.IllegalArgumentException: Invalid column count(*) AS count
    E/AndroidRuntime(25416): 	at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:170)
    E/AndroidRuntime(25416): 	at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:140)
    E/AndroidRuntime(25416): 	at android.content.ContentProviderProxy.query(ContentProviderNative.java:423)
    E/AndroidRuntime(25416): 	at android.content.ContentResolver.query(ContentResolver.java:944)
    E/AndroidRuntime(25416): 	at android.content.ContentResolver.query(ContentResolver.java:880)
    E/AndroidRuntime(25416): 	at android.content.ContentResolver.query(ContentResolver.java:836)
    E/AndroidRuntime(25416): 	at com.example.media_gallery.MediaGalleryPlugin.listImages(MediaGalleryPlugin.kt:233)
    E/AndroidRuntime(25416): 	at com.example.media_gallery.MediaGalleryPlugin.access$listImages(MediaGalleryPlugin.kt:18)
    E/AndroidRuntime(25416): 	at com.example.media_gallery.MediaGalleryPlugin$onMethodCall$3.invoke(MediaGalleryPlugin.kt:66)
    E/AndroidRuntime(25416): 	at com.example.media_gallery.MediaGalleryPlugin$onMethodCall$3.invoke(MediaGalleryPlugin.kt:18)
    E/AndroidRuntime(25416): 	at com.example.media_gallery.doAsync.doInBackground(MediaGalleryPlugin.kt:531)
    E/AndroidRuntime(25416): 	at com.example.media_gallery.doAsync.doInBackground(MediaGalleryPlugin.kt:525)
    E/AndroidRuntime(25416): 	at android.os.AsyncTask$3.call(AsyncTask.java:378)
    E/AndroidRuntime(25416): 	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    E/AndroidRuntime(25416): 	... 4 more
    I/Process (25416): Sending signal. PID: 25416 SIG: 9
    

    Apparently the error happens due to this error : Invalid column count(*) AS count.

    IMPORTANT

    It seems after some testing that this error only appears with versions Android APi 29 and plus. The crashes happen probably due to one of this Android changes

    Does someone know how to fix this?

    question 
    opened by Letalus 4
  • What is a thumbnail?

    What is a thumbnail?

    Hi, thanks for your awesome package. Really saves me a lot of time. However I don't quite understand what the Future<List<int>> that is returned by the getThumbnail() call represents.

    question 
    opened by Wizzel1 1
  • MediaGallery.listMediaCollections() still getting recently deleted files

    MediaGallery.listMediaCollections() still getting recently deleted files

    My experience in native android development is pretty much close to nil so I'm not sure if this is a bug in the package or an android "feature" that needs further handling, but after deleting files in my app, and I call the MediaGallery.listMediaCollections() again at some point to refresh the list, the deleted files would still be in the list with the same item count even when the album is already empty. Even reinstalling my app doesn't fix it. Only by accessing the directory on my PC via USB and then reopening the app would strangely fix it. Judging by the behavior, I'm guessing it's an android thing that I'm not aware of. Shedding some light to this issue would be greatly appreciated.

    bug 
    opened by jj-gh 1
  • null-safety and pull request permission

    null-safety and pull request permission

    Hi,

    I converted the Dart code of this package to support the incoming null-safety feature of Flutter (currently on the beta channel). If you are interested, I would like to open a PR and so, I would need the Github permission.

    Thanks in advance, JeyPay

    opened by JeyPay 0
  • Android 11 Image and Video not in sequence (created by time).

    Android 11 Image and Video not in sequence (created by time).

    Images and videos are in random sequence in album view and collection view in Android 10 and Android 11.

    I tried sorting using:

    List<MediaPage> pages = [];
    
          pages.add(
            await widget.collection.getMedias(
              mediaType: widget.mediaType,
              take: 50,
            ),
          );
    
    pages.first.items..sort((x, y) => x.creationDate.compareTo(y.creationDate)); 
    

    but it didn't work

    On android less than 10 it is working as expected.

    opened by Sahil-Colco 0
  • App crashes on Android 11 - SDK 30 (Invalid token LIMIT in getCollectionThumbnail)

    App crashes on Android 11 - SDK 30 (Invalid token LIMIT in getCollectionThumbnail)

    After settings compiledSdkVersion to 30 the app crashes every time I try to get collections or medias.

    E/AndroidRuntime( 6991): 	at android.os.AsyncTask$4.done(AsyncTask.java:415)
    E/AndroidRuntime( 6991): 	at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
    E/AndroidRuntime( 6991): 	at java.util.concurrent.FutureTask.setException(FutureTask.java:252)
    E/AndroidRuntime( 6991): 	at java.util.concurrent.FutureTask.run(FutureTask.java:271)
    E/AndroidRuntime( 6991): 	at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:305)
    E/AndroidRuntime( 6991): 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
    E/AndroidRuntime( 6991): 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
    E/AndroidRuntime( 6991): 	at java.lang.Thread.run(Thread.java:923)
    E/AndroidRuntime( 6991): Caused by: java.lang.IllegalArgumentException: Invalid token LIMIT
    E/AndroidRuntime( 6991): 	at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:172)
    E/AndroidRuntime( 6991): 	at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:142)
    E/AndroidRuntime( 6991): 	at android.content.ContentProviderProxy.query(ContentProviderNative.java:472)
    E/AndroidRuntime( 6991): 	at android.content.ContentResolver.query(ContentResolver.java:1183)
    E/AndroidRuntime( 6991): 	at android.content.ContentResolver.query(ContentResolver.java:1115)
    E/AndroidRuntime( 6991): 	at android.content.ContentResolver.query(ContentResolver.java:1071)
    E/AndroidRuntime( 6991): 	at com.example.media_gallery.MediaGalleryPlugin.getCollectionThumbnail(MediaGalleryPlugin.kt:427)
    E/AndroidRuntime( 6991): 	at com.example.media_gallery.MediaGalleryPlugin.access$getCollectionThumbnail(MediaGalleryPlugin.kt:20)
    E/AndroidRuntime( 6991): 	at com.example.media_gallery.MediaGalleryPlugin$onMethodCall$7.invoke(MediaGalleryPlugin.kt:92)
    E/AndroidRuntime( 6991): 	at com.example.media_gallery.MediaGalleryPlugin$onMethodCall$7.invoke(MediaGalleryPlugin.kt:20)
    E/AndroidRuntime( 6991): 	at com.example.media_gallery.doAsync.doInBackground(MediaGalleryPlugin.kt:538)
    E/AndroidRuntime( 6991): 	at com.example.media_gallery.doAsync.doInBackground(MediaGalleryPlugin.kt:532)
    E/AndroidRuntime( 6991): 	at android.os.AsyncTask$3.call(AsyncTask.java:394)
    E/AndroidRuntime( 6991): 	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    E/AndroidRuntime( 6991): 	... 4 more
    Lost connection to device.
    

    The error seems to be in the getCollectionThumbnail() function with: "Invalid token LIMIT".

    Tested this on Android Emulator with Pixel 4XL API 30 and media_gallery: 0.1.5.

    opened by AdrianSima 3
  • Issue getting .heic pictures on ios

    Issue getting .heic pictures on ios

    it looks like the platform channels returns null path for this type of files and so it throws an exception because

    File(path);
    

    requires a valid path.

    opened by imtoori 0
Owner
Aloïs Deniel
Flutter Freelance
Aloïs Deniel
A showcase app for displaying image lists, developed on Flutter.

flutter_showcase_app Pixabay: A Flutter demo application. A showcase app for displaying image lists, developed on Flutter. Uses BLOC pattern, SQFLite

Muhammad Umair Adil 26 Nov 25, 2022
Flutter package for drag-and-drop reordering of two-level lists

drag_and_drop_lists Two-level drag and drop reorderable lists. Features Reorder elements between multiple lists Reorder lists Drag and drop new elemen

Philip Brink 168 Dec 18, 2022
Flutter plugin that saves images and videos to devices gallery

Gallery Saver for Flutter Saves images and videos from network or temporary file to external storage. Both images and videos will be visible in Androi

Carnegie Technologies 131 Nov 25, 2022
how to Integrating facebook audience network to flutter app for banner, interstitial, rewarded, native and native banner

fb_ads_flutter_12 A new Flutter project. Getting Started Watch the complite tutorial for integrating Facebook ads into the Flutter app in our Youtube

null 4 Nov 26, 2022
Flutter native ads - Show AdMob Native Ads use PlatformView

flutter_native_ads Flutter plugin for AdMob Native Ads. Compatible with Android and iOS using PlatformView. Android iOS Getting Started Android Androi

sakebook 64 Dec 20, 2022
react-native native module for In App Purchase.

Documentation Published in website. Announcement Version 8.0.0 is currently in release candidate. The module is completely rewritten with Kotlin and S

dooboolab 2.3k Dec 31, 2022
Flutter package to simplify pagination of list of items from the internet.

PaginationView Installing In your pubspec.yaml dependencies: pagination_view: ^2.0.0-nullsafety.0 import 'package:pagination_view/pagination_view.da

Venkatesh Prasad 151 Dec 29, 2022
Flutter Bidirectional ListView - ListView with items that can be scrolled in both directions with a fixed item count and scroll boundaries.

Flutter Bidirectional ListView ListView with items that can be scrolled and lazy loaded in up and down direction with a fixed item count and scroll bo

Christoph Rothermel 7 May 30, 2022
Flutter package that provide selectable items in list like Column

vertical_picker vertical_picker is flutter package that you can use it as item selector. users with this package be able to select item that is in ver

Sajad Rahimi 6 Nov 19, 2022
A Flutter ListView in which items can be grouped into sections.

Grouped list package for Flutter. Now with beta support for null safety! A flutter ListView in which list items can be grouped to sections. Features S

Dimitrios Begnis 277 Dec 26, 2022
Flutter package to simplify pagination of list of items from the internet.

PaginationView Installing In your pubspec.yaml dependencies: pagination_view: ^2.0.0-nullsafety.0 import 'package:pagination_view/pagination_view.da

Venkatesh Prasad 151 Dec 29, 2022
An extension of the Flutter ListView widget for incrementally loading items upon scrolling

incrementally_loading_listview An extension of the Flutter ListView widget for incrementally loading items upon scrolling. This could be used to load

Michael Bui 174 Sep 27, 2022
Receipt app to list items on a receipt with AI receipt-interpreter. Made with Flutter by Futhark AS

Receipt Recognizer Summary Extracts data from an image of a receipt, storing it in a structured format. The application is created using Flutter and t

Futhark 2 Dec 15, 2022
An app that opens Facebook, Google, Youtube by Click on the navigation bar items specifically for each.

navbutton A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started if thi

dev_allauddin 3 Feb 3, 2022
Lost and Found is an app to help people find their lost items.

lost_and_found A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started i

SonaCodeur 1 Jan 20, 2022
A grid that supports both dragging and tapping to select its items

drag_select_grid_view A grid that supports both dragging and tapping to select its items. Basic usage DragSelectGridView constructor is very similar t

Hugo Passos 121 Dec 11, 2022
A ListView that allows you to group list items and support headers like iOS UITableView section.

GroupListView package for Flutter. A ListView that allows you to group list items and support headers like iOS UITableView section. Features List Item

Daniel Ioannou 73 Nov 21, 2022
Museum Gallery Mobile App Built With Flutter

Mobile Museum картинная галерея на вашем устройстве Просматривайте ваши любимые картины на лету. Еженедельная подборка картин, собранная вручную Подро

null 3 Nov 17, 2022
its just take image from gallery or camera and save to file (in flutter)

flutter_img_pdf A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started

vivek kumar 0 Dec 28, 2021