【发布时间】:2020-12-24 15:03:11
【问题描述】:
我正在创建一个应用程序来为用户显示最新的燃油价格,并且我在我的 Firebase Firestore 数据库上使用快照侦听器,据我了解,只有在我更新数据库...我已将其安装在 1 台设备上,并为该设备获得 33 次读取!
连接到 Firebase 的代码是:
StreamBuilder<DocumentSnapshot>(
stream: FirebaseFirestore.instance
.collection('global')
.doc('inland')
.snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData) {
return Text("Loading...",
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.w700,
fontSize: 34.0));
}
if (snapshot.hasError) {
return Text("Error",
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.w700,
fontSize: 34.0));
}
if (snapshot.connectionState ==
ConnectionState.waiting) {
return Text("Loading...",
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.w700,
fontSize: 34.0));
} else {
Map<String, dynamic> document =
snapshot.data.data();
return Text("R " + document['95'],
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.w700,
fontSize: 34.0));
}
它在一个 AnimatedContainer 中,但据我了解,当它在数据库上没有改变时,应用程序会显示缓存中的价格,所以这应该没什么区别。
我理解错了吗?有没有办法解决这个问题?
【问题讨论】:
标签: firebase flutter google-cloud-firestore