Reputation: 41
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,
};
Upvotes: 4
Views: 2976
Reputation: 250
onComplete does not have any more but there is different method is whenComplete may replace what you need.
await ref.putFile(image).whenComplete(() => doSomething());
Upvotes: 1
Reputation: 317497
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.
Upvotes: 5