【发布时间】:2021-06-07 05:10:33
【问题描述】:
我有一个完整的工作项目并将 Flutter 更新到 2.0,并将完整的项目更新为 null 安全。
现在从 firebase 获取数据的第一步也是基本的步骤不适用于网络。
@override
void initState() {
super.initState();
appState = AppState.loading;
loadData();
}
void loadData() async {
QuerySnapshot val = await FirebaseFirestore.instance
.collection(FirestoreFields.APPDATA_COLLECTION)
.get();
setState(() {
if (val.docs.length == 0)
appState = AppState.databaseSetupPending;
else
appState = AppState.databaseDownloading;
});
}
这段代码在 Flutter for web 上给了我以下错误。
Error: [cloud_firestore/unknown] Expected a value of type '((Object?) => Object)?', but got one of type '(Object) => Object?'
at Object.throw_ [as throw] (http://localhost:60662/dart_sdk.js:5032:11)
at collection_reference_web.CollectionReferenceWeb.new.get (http://localhost:60662/packages/cloud_firestore_web/src/write_batch_web.dart.lib.js:370:23)
at get.next (<anonymous>)
at http://localhost:60662/dart_sdk.js:37210:33
at _RootZone.runUnary (http://localhost:60662/dart_sdk.js:37081:59)
at _FutureListener.thenAwait.handleValue (http://localhost:60662/dart_sdk.js:32337:29)
at handleValueCallback (http://localhost:60662/dart_sdk.js:32864:49)
at Function._propagateToListeners (http://localhost:60662/dart_sdk.js:32902:17)
at _Future.new.[_completeWithValue] (http://localhost:60662/dart_sdk.js:32750:23)
at async._AsyncCallbackEntry.new.callback (http://localhost:60662/dart_sdk.js:32771:35)
at Object._microtaskLoop (http://localhost:60662/dart_sdk.js:37333:13)
at _startMicrotaskLoop (http://localhost:60662/dart_sdk.js:37339:13)
at http://localhost:60662/dart_sdk.js:33110:9
但同样的项目在我的安卓设备上运行完美。
我所有其他不使用 firebase 的项目在更新并使其为 null 安全后也可以在网络上完美运行。
这是我的 index.html 文件:
https://developers.google.com/web/fundamentals/primers/service-workers -->
<script src="https://www.gstatic.com/firebasejs/8.2.10/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.2.10/firebase-auth.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.2.10/firebase-firestore.js"></script>
<script>
// Your web app's Firebase configuration
// For Firebase JS SDK v7.20.0 and later, measurementId is optional
var firebaseConfig = {
apiKey: "*******************************",
authDomain: "*******************************",
projectId: "*******************************",
storageBucket: "*******************************",
messagingSenderId: "*******************************",
appId: "**************************************************************",
measurementId: "*******************************"
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
</script>
【问题讨论】:
-
您好,我建议您查看以下链接Migration Guide,它将帮助您检查您是否升级到了最新推荐的稳定版本。检查这一点很重要,因为通常您必须等待使用某个新版本,因为它可能有某些需要修复的东西。如果检查后仍有问题,请告诉我。
标签: firebase flutter dart google-cloud-firestore