'Firebase Storage await uploadTask.onComplete outdated

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,
          };


Solution 1:[1]

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.

Solution 2:[2]

onComplete does not have any more but there is different method is whenComplete may replace what you need.

await ref.putFile(image).whenComplete(() => doSomething());

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Doug Stevenson
Solution 2 ??o Ph?m