The zap_picker
package is a versatile Flutter package designed to simplify media and file picking in your Flutter applications. With zap_picker
, you can effortlessly integrate functionality to pick media, including images and videos, from both the gallery and video apps installed on the user's system.
The pickMedia
function allows you to seamlessly pick images or videos based on your application's requirements. It utilizes the MethodChannel
to communicate with the native platform, ensuring a smooth media picking experience. The function returns the file path of the picked media.
To ensure proper functionality of the zap_picker
package on Android, it is essential to include the necessary permissions for reading and writing external storage in your AndroidManifest.xml
file.
Add the following lines within the <manifest>
element of your AndroidManifest.xml
file:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
-
PickerType pickerType The type of picker to be used ( Gallery, File )
-
MediaType mediaType The type of media to be picked ( Image, Video )
import 'package:zap_picker/zap_picker.dart';
// Example: Pick an image from the gallery
String? imagePath = await ZapPicker.pickMedia(
pickerType: PickerType.Gallery,
mediaType: MediaType.Image,
);
The pickFile
function enables you to pick a file based on the specified file type and optional custom type. Similar to pickMedia, it utilizes the MethodChannel to communicate with the native platform, providing a consistent file picking experience. The function returns the file path of the picked file.
-
FileType fileType The specific type of file to be picked (PDF, Image, AnyType, Video, OtherType)
-
customType (Optional) List of custom file types if you selected fileType.OtherType to be picked
import 'package:zap_picker/zap_picker.dart';
// Example: Pick a PDF file
String? pdfPath = await ZapPicker.pickFile(
fileType: FileType.PDF,
);
// Example: Pick a custom file type (e.g., TXT, DOC)
String? customFilePath = await ZapPicker.pickFile(
fileType: FileType.OtherType,
customType: ['txt', 'doc'],
);