我正在使用这段代码。 错误信息如下: 错误:没有为类型“UploadTask”定义 getter“onComplete”。 (undefined_getter 在 [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,
};
最佳答案
我不确定您从哪里得知 UploadTask 上有一个名为 onComplete
的方法。如果您遵循 documentation 中的示例代码,你会看到你只是直接等待 UploadTask:
await storageReference.putFile(_image);
storageReference.getDownloadURL().then(...);
您可能还想查看 handling tasks 上的文档.
关于Firebase 存储等待 uploadTask.onComplete 已过时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64945712/