How to Select Multiple Images From image_picker in Flutter?
Last Updated :
28 Apr, 2025
In some scenarios, we have to select multiple images from our device. It is difficult to select images one by one if have to select images of more than 3. So in this article, you will learn how to select multiple images from the device gallery and will display them in our UI also. You can even set the max height, width, imageQuality of the image after it is selected. Refer to this article Gallery Access and Camera in Flutter.
Step By Step Implementation
Step 1: Create a New Project in Android Studio
To set up Flutter Development on Android Studio please refer to Android Studio Setup for Flutter Development, and then create a new project in Android Studio please refer to Creating a Simple Application in Flutter.
Step 2: Create a variable for a list of images and image picker
Dart
List<File> selectedImages = []; // List of selected image
final picker = ImagePicker(); // Instance of Image picker
Step 3: Create a button for selecting multiple images
Dart
// Button to select multiple images function you
// can change theme button as per your requirement
ElevatedButton(
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all(Colors.green)),
// TO change button color
child: const Text('Select Image from Gallery and Camera'),
onPressed: () {
getImages();
},
),
Step 4: Show images in the grid view builder
Dart
Expanded(
child: SizedBox(
width: 300.0, // To show images in particular area only
child: selectedImages.isEmpty // If no images is selected
? const Center(child: Text('Sorry nothing selected!!'))
// If atleast 1 images is selected
: GridView.builder(
itemCount: selectedImages.length,
gridDelegate:
const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 3
// Horizontally only 3 images will show
),
itemBuilder: (BuildContext context, int index) {
// TO show selected file
return Center(
child: kIsWeb
? Image.network(
selectedImages[index].path)
: Image.file(selectedImages[index]));
// If you are making the web app then you have to
// use image provider as network image or in
// android or iOS it will as file only
},
),
),
),
Step 5: Add Function to button to select images
Dart
Future getImages() async {
final pickedFile = await picker.pickMultiImage(
imageQuality: 100, // To set quality of images
maxHeight: 1000, // To set maxheight of images that you want in your app
maxWidth: 1000); // To set maxheight of images that you want in your app
List<XFile> xfilePick = pickedFile;
// if atleast 1 images is selected it will add
// all images in selectedImages
// variable so that we can easily show them in UI
if (xfilePick.isNotEmpty) {
for (var i = 0; i < xfilePick.length; i++) {
selectedImages.add(File(xfilePick[i].path));
}
setState(
() { },
);
} else {
// If no image is selected it will show a
// snackbar saying nothing is selected
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Nothing is selected')));
}
}
Complete Code
Dart
import 'dart:io';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(primaryColor: Colors.green),
home: const MultipleImageSelector(),
debugShowCheckedModeBanner: false,
);
}
}
class MultipleImageSelector extends StatefulWidget {
const MultipleImageSelector({super.key});
@override
State<MultipleImageSelector> createState() => _MultipleImageSelectorState();
}
class _MultipleImageSelectorState extends State<MultipleImageSelector> {
List<File> selectedImages = [];
final picker = ImagePicker();
@override
Widget build(BuildContext context) {
// display image selected from gallery
return Scaffold(
appBar: AppBar(
title: const Text('Multiple Images Select'),
backgroundColor: Colors.green,
actions: const [],
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const SizedBox(
height: 20,
),
ElevatedButton(
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all(Colors.green)),
child: const Text('Select Image from Gallery and Camera'),
onPressed: () {
getImages();
},
),
const Padding(
padding: EdgeInsets.symmetric(vertical: 18.0),
child: Text(
"GFG",
textScaleFactor: 3,
style: TextStyle(color: Colors.green),
),
),
Expanded(
child: SizedBox(
width: 300.0,
child: selectedImages.isEmpty
? const Center(child: Text('Sorry nothing selected!!'))
: GridView.builder(
itemCount: selectedImages.length,
gridDelegate:
const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 3),
itemBuilder: (BuildContext context, int index) {
return Center(
child: kIsWeb
? Image.network(selectedImages[index].path)
: Image.file(selectedImages[index]));
},
),
),
),
],
),
),
);
}
Future getImages() async {
final pickedFile = await picker.pickMultiImage(
imageQuality: 100, maxHeight: 1000, maxWidth: 1000);
List<XFile> xfilePick = pickedFile;
setState(
() {
if (xfilePick.isNotEmpty) {
for (var i = 0; i < xfilePick.length; i++) {
selectedImages.add(File(xfilePick[i].path));
}
} else {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Nothing is selected')));
}
},
);
}
}
For Android:
Add this permission to android/app/src/main/AndroidManifest.xml
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.INTERNET"/>
For iOS:
Add the following keys to your Info.plist file, located in <project root>/ios/Runner/Info.plist:
NSPhotoLibraryUsageDescription
NSCameraUsageDescription
NSMicrophoneUsageDescription
Output:
1. When No images are selected Â
Â
2. When you pressed the button but nothing is selected
Â
3. When you selected imagesÂ
 Video Output:
Similar Reads
How to Add Multiple Markers on Google Map in Flutter?
Google Maps is one of the popular apps used nowadays for navigation or locating markers on Google Maps. We have seen markers on Google Maps for various locations. In this article, we are going to see how to implement multiple markers on Google Maps in Flutter. Step By Step ImplementationStep 1: Crea
4 min read
How to Import Data From One Page to Another in Flutter?
Flutter is Googleâs Mobile SDK to build native iOS and Android, Desktop (Windows, Linux, macOS), Web apps from a single codebase. When building applications with Flutter everything towards Widgets â the blocks with which the flutter apps are built. They are structural elements that ship with a bunch
5 min read
Flutter - How to Use SVG Image
SVG (Scalable Vector Graphics) is a vector image format that can be used to create high-quality, resolution-independent graphics. In Flutter, you can use SVG images to display vector graphics in your app. To use SVG images in Flutter, you can use the  flutter_svg package to display SVG images in Flu
3 min read
How to Install Shared Preferences in Flutter?
Shared preferences in flutter applications are used to store data in Local Storage. Shared Preferences store the data in a key-value pair. and we can also get data in a key-value pair using inbuilt functions. We can save large data in local storage or our Phone storage with the help of SQLite databa
2 min read
How to Select Video from Camera and Gallery in Flutter?
We can add video from the gallery as well as from the camera using the image_picker package in Flutter. For this, youâll need to use your real device or web version. Follow the below steps to display the images from the gallery: Step By Step Implementation Step 1: Create a New Project in Android Stu
4 min read
Flutter - Load Images with image.file
In this article, we will learn how to show file images in Flutter. There is an image widget available in Flutter. In that, you may have to use Image.network, Image.asset, Image.memory. But have you used Image.file? Maybe you have used it. If not then Let's learn about this. Sometimes we have to show
4 min read
Flutter - Select Single and Multiple Files From Device
We will explore how to select single, or multiple files from our device with different conditions. Sometimes it happens that we want to select only a single type of file or with a fixed extension. If you are looking for the same just read the article till the end. Step By Step Implementation 1. Crea
6 min read
How to Save the File in Phone Storage in Flutter?
Like in Instagram, we can save stories, and reels on our devices. We also want to save some information or some file on our device in android we will keep the file from the flutter app on android devices. Step By Step Implementation Step 1: Create a New Project in Android Studio To set up Flutter De
3 min read
How to Move Camera to any Position in Google Maps in Flutter?
Google Maps is of the most used application nowadays for navigation. If search for any location our camera on Google Map moves to that position. In this article, we are going to see how to Move the Camera to any Position in Google Maps in Flutter. Step By Step ImplementationStep 1: Create a New Pro
4 min read
How to Shuffle a List using shuffle() in Flutter?
In this article, we are going to learn how to develop an Android app in Flutter that shuffles the content of a list by calling shuffle( ). Here we will take the Benefits of the inbuilt shuffle() method from the dart:math library, which provides an easy approach to randomly arrange the items on a lis
4 min read