pickImage function

Future<String> pickImage(
  1. String collection,
  2. ImageSource source,
  3. int imageQuality
)

Implementation

Future<String> pickImage(
    String collection, ImageSource source, int imageQuality) async {
  XFile? image = await ImagePicker().pickImage(source: source);
  if (image == null) {
    return "";
  }

  Reference ref = FirebaseStorage.instance
      .ref()
      .child("$collection/${DateTime.now().microsecondsSinceEpoch}");
  UploadTask uploadTask = ref.putFile(File(image.path));

  try {
    await uploadTask;
    String? profile = await ref.getDownloadURL();
    return profile;
  } catch (e) {
    return handleFirebaseStorageError(e);
  }
}