Firebase Storage await uploadTask.onComplete outdated
1,832
I'm not sure where you got the idea that there is a method called onComplete
on the UploadTask. If you follow the example code in the documentation, you will see that you just await the UploadTask directly:
await storageReference.putFile(_image);
storageReference.getDownloadURL().then(...);
You might also want to review the docs on handling tasks.
Author by
Leob
Updated on December 25, 2022Comments
-
Leob over 1 year
Im using this code. The error message is the following: error: The getter 'onComplete' isn't defined for the type 'UploadTask'. (undefined_getter at [chatneu] lib/Screens/HomeScreen.dart:289)
Future uploadFile() async { try { pr = new ProgressDialog(context); await ImagePicker().getImage( source: ImageSource.gallery).then((image) { setState(() { _image = image as File; //klammern weg bei ImagePicker und .getImage zu Pickimage }); }); await pr.show(); Reference storageReference = FirebaseStorage.instance.ref().child( '${loggedInUser.uid}/UserProfille/${Path.basename(_image.path)}'); UploadTask uploadTask = storageReference.putFile(_image); await uploadTask.onComplete; print('File Uploaded'); storageReference.getDownloadURL().then((fileURL) { setState(() { FirebaseFirestore.instance.collection('Users').doc(loggedInUser.uid); Map<String, String> data = { 'photoUrl': fileURL, };
-
Petar Bivolarski over 2 yearsJust bumped here by following an apparently outdated Flutter tutorial for uploading Firebase images. FYI, there was a class before called
StorageUploadTask
that hadonComplete
method.