Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/aloisdeniel/media_gallery
A Flutter plugin that lists native gallery items.
https://github.com/aloisdeniel/media_gallery
dart flutter gallery image plugin video
Last synced: 12 days ago
JSON representation
A Flutter plugin that lists native gallery items.
- Host: GitHub
- URL: https://github.com/aloisdeniel/media_gallery
- Owner: aloisdeniel
- License: mit
- Created: 2020-04-30T10:25:41.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-06-08T15:59:54.000Z (over 3 years ago)
- Last Synced: 2024-10-12T22:43:10.290Z (26 days ago)
- Topics: dart, flutter, gallery, image, plugin, video
- Language: Dart
- Homepage:
- Size: 423 KB
- Stars: 86
- Watchers: 8
- Forks: 33
- Open Issues: 21
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Media Gallery plugin for Flutter
[![pub package](https://img.shields.io/pub/v/media_gallery.svg)](https://pub.dartlang.org/packages/media_gallery)
A Flutter plugin that lists native gallery items.
## Installation
First, add `media_gallery` as a [dependency in your pubspec.yaml file](https://flutter.io/platform-plugins/).
### iOS
Add the following keys to your _Info.plist_ file, located in `/ios/Runner/Info.plist`:
```xml
NSPhotoLibraryUsageDescription
Example usage description
```### Android
Add the following permissions to your _AndroidManifest.xml_, located in `/android/app/src/main/AndroidManifest.xml`:
```xml
```
You should also manage those permissions (for example thanks to the [permission_handler](https://pub.dev/packages/permission_handler) plugin). You can see an [example](example) for more details.
### Usage
#### Listing media collections
``` dart
final List collections = await MediaGallery.listMediaCollections(
mediaTypes: [MediaType.image, MediaType.video],
);
```#### Listing medias in a collection
``` dart
final MediaPage imagePage = await collection.getMedias(
mediaType: MediaType.image,
take: 500,
);
final MediaPage videoPage = await collection.getMedias(
mediaType: MediaType.video,
take: 500,
);
final List allMedias = [
...imageRange.items,
...videoRange.items,
]
..sort((x, y) => y.creationDate.compareTo(x.creationDate));
```#### Loading more medias in a collection
```dart
if (!imagePage.isLast) {
final nextImagePage = await imagePage.nextPage();
// ...
}
```#### Getting a file
```dart
final File file = await media.getFile();
```#### Getting thumbnail data
```dart
final List data = await media.getThumbnail();
```#### Displaying thumbnails
`MediaThumbnailProvider`, `MediaCollectionThumbnailProvider` are available to display thumbnail images (here with the help of [transparent_image](https://pub.dev/packages/transparent_image)) :
```dart
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](https://pub.dev/packages/transparent_image)):
```dart
FadeInImage(
fit: BoxFit.cover,
placeholder: MemoryImage(kTransparentImage),
image: MediaImageProvider(
media: media,
),
)
```To display a video, you can use [video_player](https://pub.dev/packages/video_player).
#### Image/Video picker
![picker](doc/picker.png)
You can build a gallery picker easily with this package.
See the [example](example) for more details.