Reputation: 83
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
Upvotes: 1
Views: 208
Reputation: 86
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'.
Upvotes: 0
Reputation: 80914
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;
});
});
});
Upvotes: 1