【发布时间】:2022-01-05 20:37:59
【问题描述】:
假设我们有ListView.bulider,它从Firstore 获取数据。
Widget build(BuildContext context) {
return FutureBuilder(
future: FirebaseFirestore.instance.collection('users').get(),
builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
if (!snapshot.hasData) {
return const Expanded(child: SizedBox()) ;
}
return ListView.builder(
itemCount: snapshot.data!.docs.length ,
itemBuilder: (context, int index) {
DocumentSnapshot documentSnapshot = snapshot.data!.docs[index];
return ListView.builder(
itemCount: snapshot.data!.docs.length ,
itemBuilder: (context, int index) {
DocumentSnapshot documentSnapshot = snapshot.data!.docs[index];
return Text(documentSnapshot['products'])
}
);
}
}
好的。我刚刚阅读了这些产品数据.. 然后我再次打开Future.Bulder 位于stfl 类中的同一页面,这算作新阅读吗?即使数据没有改变
也就是说,既然stfl class会再次获取数据,那么用户每次打开同一个页面多次都会计算一个新的读数吗?
和StreamBuilder一样吗?
我是否应该通过软件干预来避免这种情况,以便我以某种方式获取一次数据,例如在应用午餐开始时获取一次数据,而不是让它们进入用户多次浏览它的普通类?
【问题讨论】:
标签: firebase flutter dart google-cloud-platform google-cloud-firestore