pickAndUploadToFirebaseStorage static method
Future<String?>
pickAndUploadToFirebaseStorage(
- BuildContext context, {
- ImageSource source = ImageSource.gallery,
- required String storagePath,
- Size compressSize = const Size(720, 1280),
- required void onError(
- String e
Picks an image from the gallery or camera and uploads it to Firebase Storage.
The context
is used to show the image picker UI.
The source
determines whether the image is picked from the gallery or the camera (default is ImageSource.gallery).
The storagePath
specifies the directory in Firebase Storage where the image will be uploaded.
The compressSize
defines the target dimensions for compressing the image (default is 720x1280).
The onError
callback is invoked in case of any error, passing the error message as a string.
Returns the download URL of the uploaded image if successful, or null if any step fails
Implementation
static Future<String?> pickAndUploadToFirebaseStorage(
BuildContext context, {
ImageSource source = ImageSource.gallery,
required String storagePath,
Size compressSize = const Size(720, 1280),
required void Function(String e) onError,
}) async {
try {
final path = await pickImage(
source: source,
onError: onError,
);
if (path == null) return null;
final url = await uploadToFirebaseStorage(
compressSize: compressSize,
storagePath: storagePath,
filepath: path,
onError: onError,
);
return url;
} catch (e) {
onError(e.toString());
return null;
}
}