我在flutter项目中从Cloud Firestore提取一些数据时遇到问题。代码如下:
void test () async {
var data = await Firestore.instance.collection("markers").getDocuments();
print("${data.documents.length}");
}
但是,在控制台上,我得到以下信息:
[VERBOSE-2:shell.cc(178)] Dart Error: Unhandled exception:
NoSuchMethodError: The method '[]' was called on null.
Receiver: null
Tried calling: []("documents")
#0 Object.noSuchMethod (dart:core/runtime/lib/object_patch.dart:50:5)
#1 new QuerySnapshot._ (file:///Users/jacobpyke/Development/flutter/v1/flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.9.6/lib/src/query_snapshot.dart:10:57)
#2 Query.getDocuments (file:///Users/jacobpyke/Development/flutter/v1/flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.9.6/lib/src/query.dart:100:26)
<asynchronous suspension>
#3 HomePage.test (package:KaffeeBar/screens/home/home_page.dart:39:63)
<asynchronous suspension>
#4 HomePage.build (package:KaffeeBar/screens/home/home_page.dart:45:5)
#5 StatelessElement.build (package:flutter/src/widgets/framework.dart:3788:28)
#6 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3735:15)
#7 Element.rebuild (package:flutter/src/widgets/fra<…>
这让我感到震惊,这是一个奇怪的错误。我的firestore结构的屏幕截图可以在此处查看:https://imgur.com/a/SeYYlGY
是的,文档内有数据,因此由于没有数据,它不应该返回Null。
任何帮助表示赞赏!
编辑:此外,在我的整个应用程序中,Firestore似乎都已停止工作。在某些区域,它仍然可以正常工作,但是在某些水獭中,它返回空值
EDIT2:似乎我试图在Android上编译该应用程序,但由于Firebase插件而无法编译。
Note: /Users/jacobpyke/Development/flutter/v1/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_core-0.3.1+1/android/src/main/java/io/flutter/plugins/firebase/core/FirebaseCorePlugin.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Note: /Users/jacobpyke/Development/flutter/v1/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_messaging-4.0.0+1/android/src/main/java/io/flutter/plugins/firebasemessaging/FlutterFirebaseInstanceIDService.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
/Users/jacobpyke/Development/flutter/v1/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_performance-0.1.0+4/android/src/main/java/io/flutter/plugins/firebaseperformance/FirebasePerformancePlugin.java:71: error: cannot access zzf
trace.start();
^
class file for com.google.android.gms.internal.firebase-perf.zzf not found
Note: /Users/jacobpyke/Development/flutter/v1/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_performance-0.1.0+4/android/src/main/java/io/flutter/plugins/firebaseperformance/FirebasePerformancePlugin.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
编辑3:在编译应用程序后,它在android上运行良好。因此,firebase GoogleInfo-Service.plst可能有问题
答案 0 :(得分:0)
事实证明,此问题是Flutter的Cloud Firestore插件中的错误的一部分。因此,此问题自更新0.9.7
起已得到解决。为了解决此问题,请将pubspec.yaml
文件中的cloud firestore插件更新为cloud_firestore: ^0.9.7
并运行flutter packages get
,可以找到源here