A complete widget which can easily pick multiple images from device and display them in UI. Also picked image can be re-ordered and removed easily.
🚀 LIVE DEMO OF EXAMPLE PROJECT: https://shubham-gupta-16.github.io/multi_image_picker_view/
- Pick multiple images
- Displayed in GridView
- Reorder picked images just by dragging
- Remove picked image
- Limit max images
- Limit image extensions
- Fully customizable UI
flutter pub add multi_image_picker_view
final controller = MultiImagePickerController();
OR
final controller = MultiImagePickerController(
maxImages: 15,
allowedImageTypes: ['png', 'jpg', 'jpeg'],
withData: true,
withReadStream: true,
images: <ImageFile>[] // array of pre/default selected images
);
Note: by setting
withData
totrue
, theImageFile
will containsbytes
. It is alwaystrue
for web. However, have in mind that enabling this on IO (iOS & Android) may result in out of memory issues if you allow multiple picks or pick huge files. Use withReadStream instead.
...
Note: by setting
withReadStream
totrue
, theImageFile
will containsreadStream
of typeStream<List<int>>
. It is alwaysfalse
for web.
MultiImagePickerView(
controller: controller,
padding: const EdgeInsets.all(10),
);
OR
MultiImagePickerView(
controller: controller,
draggable: /* true or false, images can be reorderd by dragging by user or not, default true */,
showAddMoreButton: /* true or false, default is true */,
showInitialContainer: /* true or false, default is true */,
initialContainerBuilder: (context, pickerCallback) {
// return custom initial widget which should call the pickerCallback when user clicks on it
},
itemBuilder: (context, image, removeCallback) {
// return custom card for image and remove button which also calls removeCallback on click
},
addMoreBuilder: (context, pickerCallback) {
// return custom card or item widget which should call the pickerCallback when user clicks on it
},
addButtonTitle: /* Default title for AddButton */,
addMoreButtonTitle: /* Default title for AddMoreButton */,
gridDelegate: /* Your SliverGridDelegate */,
onDragBoxDecoration: /* BoxDecoration when item is dragging */,
onChange: (images) {
// callback to update images
},
);
Picked Images can be get from controller.
final images = controller.images; // return Iterable<ImageFile>
for (final image in images) {
if (image.hasPath)
request.addFile(File(image.path!));
else
request.addFile(File.fromRawPath(image.bytes!));
}
request.send();
Also controller can perform more actions.
controller.pickImages()
controller.hasNoImages // return bool
controller.maxImages // return maxImages
controller.allowedImageTypes // return allowedImageTypes
controller.removeImage(imageFile) // remove image from the images
controller.clearImages() // remove all images (clear selection)
controller.reOrderImage(oldIndex, newIndex) // reorder the image
The ImageFile class holds the selected image. It contains name
, extension
, bytes?
, readStream?
, and path?
.
path
is always null for web. And by default bytes
is null for IO (Android and IOS). To get the bytes
on IO devices, set withData
to true in MultiImagePickerController
.
However, have in mind that enabling this on IO (iOS & Android) may result in out of memory issues if you allow multiple picks or pick huge files. Use withReadStream
instead.
The readStream
is always null for web. And by default readStream
is null for IO (Android and IOS). To get the readStream
on IO devices, set withReadStream
to true in MultiImagePickerController
Note: For Web Platform, ImageFile contains
bytes
and it can't be null.
This widget helps to display image which is stored in ImageFile
. This is a replacement for Image.network
or Image.memory
widget. With this widget, it can be easy to show image just by passing the ImageFile
object.
ImageFileView(
file: imageFileObject,
fit: BoxFit.cover
)
- view_model_x - An Android similar state management package (StateFlow and SharedFlow with ViewModel) which helps to implement MVVM pattern easily.
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.