firebase - 为什么 Flutter 会因为明显存在的 "missing getter"而失败?

标签 firebase flutter firebase-storage

<分区>

Flutter 提示 firebase_storage::StorageUploadTask 上缺少 getter,但是当我打开声明时,它就在那里。

/flutter ( 3107): [ERROR:flutter/shell/common/shell.cc(182)] Dart 
Error: Unhandled exception:
E/flutter ( 3107): 'package:flutter_project/widgets/screen.dart': error: line 284 pos 43: lib/widgets/camera_screen.dart:284:43: Error: The getter 'future' isn't defined for the class 'firebase_storage::StorageUploadTask'.
E/flutter ( 3107): Try correcting the name to the name of an existing getter, or defining a getter or field named 'future'.
E/flutter ( 3107):     final downloadUrl = (await uploadTask.future).downloadUrl;
E/flutter ( 3107):                                           ^

Firebase Storage 代码(您可以看到“get future”是该类中的最后一项。):

abstract class StorageUploadTask {
  final FirebaseStorage _firebaseStorage;
  final String _path;
  final StorageMetadata _metadata;

  StorageUploadTask._(this._firebaseStorage, this._path, this._metadata);
  Future<void> _start();

  Completer<UploadTaskSnapshot> _completer =
      new Completer<UploadTaskSnapshot>();
  Future<UploadTaskSnapshot> get future => _completer.future;
}

Flutter Doctor 输出:

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel master, v0.10.1-pre.39, on Mac OS X 10.14 18A391, locale en-US)
[✓] Android toolchain - develop for Android devices (Android SDK 27.0.3)
[✓] iOS toolchain - develop for iOS devices (Xcode 10.0)
[✓] Android Studio (version 3.1)
[!] IntelliJ IDEA Community Edition (version 2017.1.5)
    ✗ Flutter plugin not installed; this adds Flutter specific functionality.
    ✗ Dart plugin not installed; this adds Dart specific functionality.
[✓] VS Code (version 1.27.2)
[✓] Connected device (1 available)

! Doctor found issues in 1 category.

来自 pubspec.yaml 的依赖:

firebase_storage: ^1.0.4

我刚刚更新了 Flutter。更新前没有这个问题,更新后才有。

此外,有时我会在编译期间遇到错误,但其他时候只有在应用程序在设备上运行后才会出现。

这根本没有意义。

编辑

显然,我在 VS Code 中使用“转到定义”工具时看到的代码不是正确的代码。我尝试执行建议的几项操作(恢复到 firebase_storage 版本 1.0.2,使用 .onComplete 而不是 .future),但这些操作均无效。所以我决定放弃过夜。

今天早上,firebase_storage 中的代码不一样了。我不确定 VS Code 是否存在缓存问题,但这似乎是问题所在。现在我看到 .future 不存在,但我可以使用 .onComplete。我更改了代码以使用 .onComplete,这很有效。

如果我使用 IntelliJ 或 Android Studio,也许我就不会遇到这个问题。

最佳答案

根据@anmol.majhail 的建议,我能够让它工作。我恢复到 firebase_storage 的 1.0.2 版,并从使用 .future 更改为 .onComplete。

它直到最初尝试几个小时后才起作用,因此似乎存在 VS Code 缓存依赖项的问题,但我不确定原因或持续时间。

关于firebase - 为什么 Flutter 会因为明显存在的 "missing getter"而失败?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52789083/

相关文章:

dart - flutter 中选择的轨道单选按钮

android - 如何将 'Google Consent ' 添加到 flutter 应用程序

android - 从 CLI 测试后如何获取 gcloud Firebase 测试实验室 Android Espresso 结果?

flutter - 使用 Flutter 嵌套和同步 ListView (类似调度程序)

ios - 你如何退出 Firebase? ( objective-C )

ios - 在 Firebase 返回结果后为变量赋值?

javascript - 'getDownloadURL' 在 Promise 中返回少一个 URL

Swift Firebase 如何停止进程?

firebase - Cloud FireStore使用相同的iD作为用户UID的多个文档

android - Firebase 云消息传递是否会自动记录分析事件?