Firebase 存储等待 uploadTask.onComplete 已过时

标签 firebase flutter dart google-cloud-firestore firebase-storage

我正在使用这段代码。 错误信息如下: 错误:没有为类型“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/

相关文章:

ios - Firebase Crashlytics集成停留在“我们将在监听您的应用程序与我们的服务器进行通信”。的iOS

swift - IOS - 从 Firebase 解析对象 - 下载完成前运行的代码

flutter - DraggableScrollableSheet 在滚动前吸附到顶部

firebase - 在Dart中从Cloud_Firestore获取 bool 状态

firebase - 如何处理 noSQL 数据库中的标签

Flutter ListView 在底部弹跳但在顶部弹跳(iOS)

firebase - 云 Firestore 中的时间字段 serverTimestamp() 在第一个快照上返回 null

dart - 如何对 map 的值进行排序?

flutter - 按像素底部溢出

html - Angular 4 firebase下拉选择标签选项