Streamline media selection, cropping, and camera features in your Flutter application

Flutter Image Picker Plugin

pub packagepub package
AndroidiOS
SupportSDK 21+11.0+
Simplify media selection, cropping, and camera functionality in your Flutter app. Choose images/videos from the library, crop images, and capture new photos/videos with ease.
Picker iOS
Picker Android

Installation

$ flutter pub add hl_image_picker
Note: If you are developing an application exclusively for either Android or iOS, you don’t need to install hl_image_picker. Instead, you can choose one of the following packages based on your target platform:

Setup

To use the plugin, you need to perform the following setup steps:
iOS
PHPhotoLibraryPreventAutomaticLimitedAccessAlert
localize camera
Android

Usage

Select images/videos from library

import 'package:hl_image_picker/hl_image_picker.dart';

final _picker = HLImagePicker();

List<HLPickerItem> _selectedImages = [];

_openPicker() async {
    final images = await _picker.openPicker(
        // Properties
    );
    setState(() {
        _selectedImages = images;
    });
}
Properties
PropertyDescriptionType
selectedIdsA list of string IDs representing the initially selected images or videos from the library. This allows users to pre-select items before opening the picker.[String]
pickerOptionsAdditional options for the pickerHLPickerOptions
croppingIndicating whether or not cropping is enabled. Just work when mediaType = MediaType.image and maxSelectedAssets = 1bool
cropOptionsConfiguration options for the cropping functionalityHLCropOptions
localizedCustom text displayed for the pluginLocalizedImagePicker

Take a photo or record a video

import 'package:hl_image_picker/hl_image_picker.dart';

final _picker = HLImagePicker();

HLPickerItem? _selectedImage;

_openCamera() async {
    final image = await _picker.openCamera(
        // Properties
    );
    setState(() {
        _selectedImage = image;
    });
}
Properties
PropertyDescriptionType
cameraOptionsAdditional options for the camera functionalityHLCameraOptions
croppingIndicating whether or not cropping is enabledbool
cropOptionsConfiguration options for the cropping functionalityHLCropOptions
localizedCustom text displayed for the pluginLocalizedImageCropper

Open image cropper

import 'package:hl_image_picker/hl_image_picker.dart';

final _picker = HLImagePicker();

HLPickerItem? _selectedImage;

_openCropper_() async {
    final image = await _picker.openCropper("image_path_to_crop",
    // Properties
    );
    setState(() {
        _selectedImage = image;
    });
}
Properties
PropertyDescriptionType
imagePathPath of the image that needs to be croppedString
croppingIndicating whether or not cropping is enabledbool
cropOptionsConfiguration options for the cropping functionalityHLCropOptions
localizedCustom text displayed for the pluginLocalizedImageCropper
Picker iOS
Picker iOS Circular
Picker Android
Picker Android Circular

HLPickerOptions

PropertyDescriptionDefault
mediaTypeType of media you want to select: MediaType.imageMediaType.video,MediaType.all.MediaType.all
maxSelectedAssetsThe maximum number of items that can be selected.1
minSelectedAssetsThe minimum number of items that must be selected.
maxFileSizeThe maximum allowed file size for selected items.
minFileSizeThe minimum allowed file size for selected items.
enablePreviewEnables or disables the preview feature. (Press on Android and Long Press on iOS)false
convertHeicToJPGConverts HEIC format images to JPEG format when selected. (iOS Only)false
convertLivePhotosToJPGConverts Live Photos to JPEG format when selected. (iOS Only)true
recordVideoMaxSecondThe maximum duration (in seconds) for recorded video.60
isExportThumbnailDetermines whether to export thumbnail for selected videos.false
thumbnailCompressQualityThe compression quality (0.1-1) for exported thumbnails.0.9
thumbnailCompressFormatThe image format for exported thumbnails: CompressFormat.jpgCompressFormat.png.CompressFormat.jpg
maxDurationThe maximum duration (in seconds) for selected videos.
minDurationThe minimum duration (in seconds) for selected videos.
numberOfColumnThe number of items displayed per row in the picker list.3
usedCameraButtonDetermines whether to show the camera button in the picker list.true

HLCropOptions

PropertyDescriptionDefault
aspectRatioSpecifies the desired aspect ratio for cropping.
aspectRatioPresetsProvides a set of predefined aspect ratio options for cropping.
compressQualityDetermines the compression quality (0.1-1) for the exported image.0.9
compressFormatSpecifies the image format for the exported image: CompressFormat.jpgCompressFormat.png.CompressFormat.jpg
croppingStyleCropping style: CroppingStyle.normalCroppingStyle.circular.CroppingStyle.normal
maxSizeOutputSets the maximum width and maximum height for the exported image.

HLCameraOptions

PropertyDescriptionDefault
cameraTypeSpecifies the type of camera to be used: CameraType.videoCameraType.imageCameraType.image
recordVideoMaxSecondThe maximum duration (in seconds) for recorded video.60
isExportThumbnailDetermines whether to export thumbnail for recorded video.false
thumbnailCompressQualityThe compression quality (0.1-1) for exported thumbnail.0.9
thumbnailCompressFormatThe image format for exported thumbnail: CompressFormat.jpgCompressFormat.png.CompressFormat.jpg

HLPickerItem (Response)

PropertyDescriptionType
pathThe path of the item.String
idThe unique identifier of the item.String
nameThe filename of the item.String
mimeTypeThe MIME type of the item.String
sizeThe size of the item in kilobytes (KB).int
widthThe width of the itemint
heightThe height of the itemint
typeIndicates whether the item is an image or video.String
durationThe duration of the videodouble?
thumbnailThe path of the video thumbnailString?

LocalizedImagePicker

PropertyDescriptionDefault
maxDurationErrorTextThe error message displayed when the selected video exceeds the maximum duration.Exceeded maximum duration of the video
minDurationErrorTextThe error message displayed when the selected video is below the minimum duration.The video is too short
maxFileSizeErrorTextThe error message displayed when the selected file exceeds the maximum file size.Exceeded maximum file size
minFileSizeErrorTextThe error message displayed when the selected file is below the minimum file size.The file size is too small
noAlbumPermissionTextThe error message displayed when the app doesn’t have permission to access the album.No permission to access album
noCameraPermissionTextThe error message displayed when the app doesn’t have permission to access the camera.No permission to access camera
maxSelectedAssetsErrorTextThe error message displayed when the maximum number of items is exceeded.Exceeded maximum number of selected items
minSelectedAssetsErrorTextThe error message displayed when the minimum number of items is not met.Need to select at least {minSelectedAssets}
noRecordAudioPermissionTextThe error message displayed when the app doesn’t have permission to record audio.No permission to record audio
doneTextThe text displayed on the “Done” button.Done
cancelTextThe text displayed on the “Cancel” button.Cancel
loadingTextThe text displayed when the picker is in a loading state.Loading
defaultAlbumNameThe name for default album.Recents
tapHereToChangeTextThe text displayed below defaultAlbumName. (iOS Only)Tap here to change
okTextThe text displayed on the “OK” button.OK
emptyMediaTextThe text displayed when no media is available. (iOS Only)No media available
cropDoneTextThe text displayed on the “Done” button. (iOS Only)Done
cropCancelTextThe text displayed on the “Cancel” button. (iOS Only)Cancel
cropTitleTextThe title displayed in the crop image screen. (iOS Only)

LocalizedImageCropper

PropertyDescriptionDefault
cropDoneTextThe text displayed on the “Done” button. (iOS Only)Done
cropCancelTextThe text displayed on the “Cancel” button. (iOS Only)Cancel
cropTitleTextThe title displayed in the crop image screen. (iOS Only)

ProGuard

-keep class com.luck.picture.lib.** { *; }
-dontwarn com.yalantis.ucrop**
-keep class com.yalantis.ucrop** { *; }
-keep interface com.yalantis.ucrop** { *; }

Open-source library

Android: PictureSelector

GitHub

Description of the image

Related Posts