gpt4 book ai didi

firebase - “task.future.then ”不断在我的Flutter代码中引发错误

转载 作者:行者123 更新时间:2023-12-03 03:33:08 25 4
gpt4 key购买 nike

这是我的代码-

    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);
});
}
这是它给的错误-
未为类型“StorageUploadTask”定义 setter/getter “future”。
尝试导入定义“future”的库,将名称更正为现有 setter/getter 的名称,或者定义一个名为“future”的 setter/getter 或字段。
虽然我已经导入了dart:async和dart:io
请帮忙,谢谢

最佳答案

StorageUploadTask没有名为future的属性,您必须使用onComplete进行以下操作:

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

关于firebase - “task.future.then ”不断在我的Flutter代码中引发错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62632860/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com