在我的应用程序中,我可以在iOS、android和web上登录(使用firebase auth(。当我尝试使用streambuilder从Firestore数据库中读取时,它只适用于iOS和android。在web部件中,它直接进入捕捉的else子句。HasData。
我的index.html-file(firebaseConfig明显删除(:
<body>
<script src="https://www.gstatic.com/firebasejs/8.3.0/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.3.0/firebase-auth.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.3.0/firebase-firestore.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.3.0/firebase-functions.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.3.0/firebase-messaging.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.3.0/firebase-analytics.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.3.0/firebase-storage.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.3.0/firebase-remote-config.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: "",
databaseURL: "",
projectId: "",
storageBucket: "",
messagingSenderId: "",
appId: "",
measurementId: ""
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
firebase.analytics();
</script>
<!-- This script installs service_worker.js to provide PWA functionality to
application. For more information, see:
https://developers.google.com/web/fundamentals/primers/service-workers -->
<script>
if ('serviceWorker' in navigator) {
window.addEventListener('flutter-first-frame', function () {
navigator.serviceWorker.register('flutter_service_worker.js');
});
}
</script>
<script src="main.dart.js" type="application/javascript"></script>
</body>
登录时我的仪表板屏幕。在我的控制台中,我得到打印";进入streambuilder";但不是印刷品";快照具有数据":
return Scaffold(
key: _scaffoldKey,
appBar: PreferredSize(
preferredSize: Size.fromHeight(70.0),
child: AppBar(
title: Padding(
padding: const EdgeInsets.only(top: 10.0),
child: StreamBuilder<List<Users>>(
stream: database.users(),
builder: (context, snapshot) {
print("enters streambuilder");
if (snapshot.hasData) {
print("snapshot has data");
final users = snapshot.data;
if (users.isNotEmpty) {
print("users is not empty");
...
这些是我的pubspec.yaml依赖项:
environment:
sdk: ">=2.2.2 <3.0.0"
dependencies:
flutter:
sdk: flutter
flutter_localizations:
sdk: flutter
firebase_core_platform_interface: 4.0.0
firebase_storage_web: 1.0.0
firebase_auth_web: 1.0.0
firebase_core: 1.0.1
firebase_core_web: 1.0.1
firebase_storage: 8.0.0
firebase_messaging: 9.0.0
firebase_dynamic_links: ^0.5.0+11
firebase_auth: 1.0.0
cloud_firestore: 1.0.0
cloud_firestore_web: 1.0.1
...
我是否缺少任何依赖项?我不明白为什么我不能从消防仓库读取数据。我仔细检查了firebaseConfig设置是否与我在firebase中的项目设置正确设置。
在这里找到了一个解决方案Stackoverflow:Flutter Web-Fetching Firestore集合
显然,使用8.3.0版本是个问题。使用7.14.4代替