1
votes

This is my code -

    Future uploadImage() async {
var randomno = Random(25);
final StorageReference firebaseStorageRef = FirebaseStorage.instance
    .ref()
    .child('profilepics/${randomno.nextInt(5000).toString()}.jpg');
StorageUploadTask task = firebaseStorageRef.putFile(selectedImage);

task.future.then((value) {
  setState(() {
    userManagement
        .updateProfilePic(value.downloadUrl.toString())
        .then((val) {
      setState(() {
        profilePicUrl = value.downloadUrl.toString();
        isLoading = false;
      });
    });
  });
}).catchError((e) {
  print(e);
});
  }

This is the error it gives -

The getter 'future' isn't defined for the type 'StorageUploadTask'. Try importing the library that defines 'future', correcting the name to the name of an existing getter, or defining a getter or field named 'future'.

Although i have already imported dart:async and dart:io Please help, thanks

2

2 Answers

1
votes

StorageUploadTask doesnt have a property called future, you have to use onComplete the following:

final StorageReference firebaseStorageRef = FirebaseStorage.instance
    .ref()
    .child('profilepics/${randomno.nextInt(5000).toString()}.jpg');
StorageUploadTask task = firebaseStorageRef.putFile(selectedImage);
task.onComplete.then((value) {
  setState(() {
    userManagement
        .updateProfilePic(value.ref.getDownloadURL().toString())
        .then((val) {
      setState(() {
        profilePicUrl = value.ref.getDownloadURL().toString();
        isLoading = false;
      });
    });
  });

https://github.com/FirebaseExtended/flutterfire/blob/master/packages/firebase_storage/lib/src/upload_task.dart#L28

0
votes

now 'onComplete' is also showing error

The getter 'onComplete' isn't defined for the type 'UploadTask'. Try importing the library that defines 'onComplete', correcting the name to the name of an existing getter, or defining a getter or field named 'onComplete'.