Developed by Totalx Software
ImagePickerTotalxsoftware
is a Flutter package for handling advanced image picking, cropping, compressing, and uploading functionalities with Firebase integration. This package simplifies the process of selecting, cropping, and uploading images to Firebase Storage.
Single Image Selection
: Choose a single image from the camera or gallery.Multiple Image Selection
: Select multiple images at once.Image Cropping
: Crop selected images with custom aspect ratios.Firebase Upload
: Upload images directly to Firebase Storage.Image Compression
: Compress images before uploading.Image Deletion
: Delete single or multiple images from Firebase Storage.
Add the package to your pubspec.yaml
:
dependencies:
image_picker_totalxsoftware: ^1.0.0
import 'package:image_picker_totalxsoftware/image_picker_totalxsoftware.dart';
Add the following permissions to your AndroidManifest.xml
:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-feature android:name="android.hardware.camera" android:required="false" />
<uses-permission android:name="android.permission.CAMERA" />
Add the following keys to your Info.plist
file:
<key>NSPhotoLibraryUsageDescription</key>
<string>We need access to your photo library to pick images.</string>
<key>NSCameraUsageDescription</key>
<string>We need access to your camera to take photos.</string>
<!-- <key>NSPhotoLibraryAddUsageDescription</key>
<string>We need permission to save edited images to your photo library.</string> -->
// file path
String? imagePath = await ImagePickerTotalxsoftware.pickImage(
source: ImageSource.gallery,
onError: (error) {
print("Error picking image: $error");
},
);
// file path
String? path = await ImagePickerTotalxsoftware.pickAndCropImage(
context,
aspectRatioPresets: [
CropAspectRatioPreset.ratio7x5,
CropAspectRatioPreset.square,
],
onError: (e) {
log(e);
},
);
// List of file paths
final paths = await ImagePickerTotalxsoftware.pickMultipleImage(
context,
maxImageCount: 5,
// minImageCount: 2,
onError: (e) {
log(e);
},
);
// List of file paths
final paths = await ImagePickerTotalxsoftware.pickMultipleImageAndCrop(
context,
maxImageCount: 5,
// minImageCount: 2,
aspectRatioPresets: [
CropAspectRatioPreset.ratio7x5,
CropAspectRatioPreset.ratio4x3,
],
cropStyle: CropStyle.rectangle,
onError: (e) {
log(e);
},
);
// String url
String? uploadedUrl = await ImagePickerTotalxsoftware.pickAndUploadToFirebaseStorage(
context,
source: ImageSource.gallery,
storagePath: 'usersImages',
onError: (error) {
print("Error uploading image: $error");
},
);
// String url
String? uploadedUrl = await ImagePickerTotalxsoftware.pickCropAndUploadToFirebaseStorage(
context,
source: ImageSource.gallery,
storagePath: 'usersImages',
cropStyle: CropStyle.circle,
onError: (error) {
print("Error uploading cropped image: $error");
},
);
// String url
String? url =await ImagePickerTotalxsoftware.uploadToFirebaseStorage(
filepath: 'path/to/file.png',
// compressSize: const Size(720, 1280),
storagePath: 'images',
onError: (e) {
log(e);
},
);
// List of urls
List<String> uploadedUrls = await ImagePickerTotalxsoftware.uploadMultipleToFirebaseStorage(
filepathList: ['path/to/image1.jpeg', 'path/to/image2.jpeg'],
storagePath: 'images',
onError: (error) {
print("Error uploading multiple images: $error");
},
);
try {
await ImagePickerTotalxsoftware.deleteImageFromFirebaseByUrl(
'https://firebasestorage.googleapis.com/v0/b/your-app-id/o/uploads/image.jpeg',
);
} catch (e) {
log('error $e')
}
try {
await ImagePickerTotalxsoftware.deleteMultipleImagesFromFirebaseByUrls([
'https://firebasestorage.googleapis.com/v0/b/your-app-id/o/uploads/image1.jpeg',
'https://firebasestorage.googleapis.com/v0/b/your-app-id/o/uploads/image2.jpeg',
]);
} catch (e) {
log('error $e')
}
Explore more about TotalX at www.totalx.in - Your trusted software development company!
Join the vibrant Flutter Firebase Kerala community for updates, discussions, and support:
Flutter Firebase Kerala Totax