Hi I am trying to save an image which is picked from gallery or camera.
Future<void> getImage({ImageSource source}) async {
_pickedImage = await ImagePicker().getImage(source: source);
if (_pickedImage != null) {
_pickedImageFile = File(_pickedImage.path);
}
}
After picking the image it has to update image to the firebase storage.
void _uploadImage(File image) async {
Reference storageReference = FirebaseStorage.instance
.ref()
.child('UserImage')
.child("UserImage/${user.uid}");
UploadTask uploadTask = storageReference.putFile(image);
//StorageTaskSnapshot taskSnapshot = await uploadTask.onComplete;
uploadTask.then((newUrl) async {
newUrl.ref.getDownloadURL();
return imageUrl = newUrl.toString();
}).catchError((onError) {
print(onError);
});
}
The issue is the code is breaking at uploadTask.then((newUrl) and not letting to get the downloadURL as a String. Then it has to update the image path to the firestore collection.
void userDetailsUpdate() {
FirebaseFirestore.instance
.collection("Manufacturer-Accounts")
.doc(user.uid)
.update({
'Designation': designation.text,
'FirstName': firstName.text,
'LastName': lastName.text,
//'Email': user.email,
'Phone': phoneNumber.text,
'UserImage': imageUrl == null ? "" : imageUrl,
});
}
Because it is not getting the image url so it is saving the value as "". Is there a way of doing it? I have used the Firebase storage ^5.0.1
My full source code is given here How can I add a new value to my text editcontroller in Text formfield?