plux_media_picker 1.0.0
plux_media_picker: ^1.0.0 copied to clipboard
A Flutter plugin that provides a unified API to pick photos, videos, and files from the device's gallery, camera, and file system.
plux_media_picker #
A Flutter plugin that provides a unified API to pick photos, videos, and files from the device's gallery, camera, and file system. Supports iOS and Android only.
Features #
- Uses native system pickers (no custom UI)
- Single or multiple selection of media files
- Built‑in image compression with adjustable quality
- File extension filtering for the file picker
- Handles Android activity recreation (returns lost results via
getLostFiles)
Installation #
Add this to your pubspec.yaml:
dependencies:
plux_media_picker: ^1.0.0
Permissions #
Android #
Add the following permissions to android/app/src/main/AndroidManifest.xml:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
For Android 13+, you may also need READ_MEDIA_IMAGES and READ_MEDIA_VIDEO.
iOS #
Add the following keys to ios/Runner/Info.plist:
<key>NSCameraUsageDescription</key>
<string>We need camera access to take photos</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>We need gallery access to select photos</string>
Usage #
First, create an instance of the plugin:
import 'package:plux_media_picker/plux_media_picker.dart';
final picker = PluxMediaPicker();
Pick from Camera #
// Take a photo
File? photo = await picker.pickCamera(mediaType: CameraMediaType.image);
// Record a video
File? video = await picker.pickCamera(mediaType: CameraMediaType.video);
// Let the user choose photo or video
File? media = await picker.pickCamera(mediaType: CameraMediaType.any);
Pick from Gallery #
List<File> images = await picker.pickGallery(
maxLimit: 10, // maximum number of items
quality: 0.8, // compression quality (0.0–1.0), applies to images only
);
Pick from File System #
List<File> files = await picker.pickFiles(
multipleSelection: true,
allowedExtensions: ['pdf', 'docx', 'png'], // case-insensitive
);
Recovering Lost Results (Android only) #
If your app is killed by the system while the picker is open, the plugin saves the selected result. To retrieve it after the activity is recreated, call getLostFiles() (e.g., in initState):
@override
void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback((_) async {
List<File> lostFiles = await picker.getLostFiles();
if (lostFiles.isNotEmpty) {
// handle the recovered files
}
});
}
Return Values & Error Handling #
pickCamerareturnsnullif the user cancels.pickGalleryandpickFilesreturn an empty list[]if nothing is selected.- In case of errors (e.g., missing permissions), the methods throw an exception – wrap calls in
try-catch.
API Reference #
| Method | Parameters | Returns | Description |
|---|---|---|---|
pickCamera |
mediaType: CameraMediaType quality: double |
Future<File?> |
Opens the camera for a single media file. |
pickGallery |
maxLimit: int (default 10), quality: double (default 0.8) |
Future<List<File>> |
Opens the gallery for media selection. |
pickFiles |
multipleSelection: bool (default false), allowedExtensions: List<String>? |
Future<List<File>> |
Opens the file manager. |
getLostFiles |
– | Future<List<File>> |
Retrieves files selected before activity recreation (Android). |
clearCache |
– | Future<bool> |
Clear temp cache. |