![](/img/trans.png)
[英]Error: Expected a value of type 'int', but got one of type 'String'; flutter
[英]Flutter Web (Firestore Error)- Expected a value of type 'JSObject<qc>', but got one of type 'NativeJavaScriptObject'
我在我的 web 項目中試用了 flutter 雲 Firestore。
我在主頻道上,我在 pubspec.yaml 文件中使用以下版本。
cloud_firestore: ^0.13.5
Index.html 文件:
<script src="https://www.gstatic.com/firebasejs/7.14.2/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/7.14.2/firebase-auth.js"></script>
<script src="https://www.gstatic.com/firebasejs/7.14.2/firebase-firestore.js"></script>
<script>
// TODO: Replace the following with your app's Firebase project configuration.
// See: https://support.google.com/firebase/answer/7015592
var firebaseConfig = {
apiKey: "--apiKey--",
authDomain: "--authDomain--",
databaseURL: "--databaseURL--",
projectId: "--testapp--",
storageBucket: "--test.appspot.com--",
messagingSenderId: "--senderId--",
appId: "--appId--"
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
在我的列表屏幕中,我正在獲取如下數據:
var reference = widget.firestore.collection('work');
print("reference : ${reference}");
try {
QuerySnapshot snapshot = await reference.getDocuments();
print("work snapshot : ${snapshot}");
} catch (error) {
print("work error : ${error}");
}
但是,在我的 flutter web 項目中嘗試從雲 Firestore 獲取數據時出現錯誤。
錯誤:
Expected a value of type 'JSObject<qc>', but got one of type 'NativeJavaScriptObject'
任何人都可以建議一個解決方法。
謝謝。
拋出錯誤的原因是因為您在reference.getDocuments()
返回不同的值類型時試圖分配QuerySnapshot
。 要獲取 Collection 中的文檔,應該使用get()方法。
CollectionReference reference = FirebaseFirestore.instance.collection('work');
QuerySnapshot snapshot = await reference.get();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.