uploadToFirebaseStorage static method

Future<String?> uploadToFirebaseStorage({
  1. required String storagePath,
  2. Size compressSize = const Size(720, 1280),
  3. required String filepath,
  4. required void onError(
    1. String e
    ),
})

Uploads a single image to Firebase Storage and returns its download URL.

Compresses the image before uploading. Calls onError in case of an error.

Implementation

static Future<String?> uploadToFirebaseStorage({
  required String storagePath,
  Size compressSize = const Size(720, 1280),
  required String filepath,
  required void Function(String e) onError,
}) async {
  try {
    final imageList = await uploadMultipleToFirebaseStorage(
      storagePath: storagePath,
      filepathList: [filepath],
      onError: onError,
    );
    return imageList.first;
  } on Exception catch (e) {
    onError(e.toString());
    return null;
  }
}