What are the differences between image picker vs file picker in flutter
An image picker
in Flutter is a plugin/library that “allows you to select an image from the device's image library” or “take a new picture with the camera.” A file picker
, on the other hand, allows you to select any type of file from the device's file system.
In other words, an image picker
is specifically for selecting image files, while a file picker
“can be used to select any type of file”, including images, documents, audio files, etc.
What is image picker
- A Flutter plugin for iOS and Android for picking images from the image library, and taking new pictures with the camera.
Implementation
// Add dependency.
flutter pub add image_picker
// Import the library.
import 'package:image_picker/image_picker.dart';
// Create an object from the ImagePicker() class.
final ImagePicker _picker = ImagePicker();
// Multimple image selection.
await _displayPickImageDialog(context!,
(double? maxWidth, double? maxHeight, int? quality) async {
try {
final List<XFile> pickedFileList = await _picker.pickMultiImage(
maxWidth: maxWidth,
maxHeight: maxHeight,
imageQuality: quality,
);
setState(() {
_imageFileList = pickedFileList;
});
} catch (e) {
setState(() {
_pickImageError = e;
});
}
});
// Single image selection.
await _displayPickImageDialog(context!,
(double? maxWidth, double? maxHeight, int? quality) async {
try {
final XFile? pickedFile = await _picker.pickImage(
source: source,
maxWidth: maxWidth,
maxHeight: maxHeight,
imageQuality: quality,
);
setState(() {
_setImageFileListFromFile(pickedFile);
});
} catch (e) {
setState(() {
_pickImageError = e;
});
}
});
.
.
.