首页 > 解决方案 > 从 Firestore 获取数据库并在 Flutter 的 RefreshIndicator 中使用

问题描述

大家好,我正在从 firestore 获取数据。在这种情况下,我试图将 RefreshIndicator() 添加到 onRefresh(); 当我只使用没有查询的数据时,我看不到任何错误,它的工作方式很清楚

tumGonderiler() async {
QuerySnapshot myQuerySnapshot = await akisRef.get();
setState(() {
  this.tEdilenGonderiler = myQuerySnapshot.docs.map((e) => e.data()).toList();
});

但是当我尝试使用 where 参数在我的集合中查询时, onRefresh () 在我的页面中不起作用,不起作用的代码如下

tumGonderiler() async {
QuerySnapshot myQuerySnapshot = await akisRef.where("ownerID", whereIn: takipEdilenKullanicilar.map((e) => e.id).toList()).get();
setState(() {
  this.tEdilenGonderiler = myQuerySnapshot.docs.map((e) => e.data()).toList();
});

}

标签: fluttergoogle-cloud-firestore

解决方案


我已经稍微更改了我的代码,直到现在它正在工作,你可以从下面跟随

tumGonderiler() async {
QuerySnapshot snapshot1 = await takipEdilenRef.doc(anlikKullanici!.id).collection("takipEdilenler").get();
List<tEdilen> kullaniciress = snapshot1.docs.map((doc) => tEdilen.fromDocument(doc)).toList();
setState(() {
  this.takipEdilenKullanicilar = kullaniciress;
});
QuerySnapshot myQuerySnapshot = await akisRef.where("ownerID", whereIn: takipEdilenKullanicilar.map((e) => e.id).toList()).get();
List<Gonderiler> kullanicires = myQuerySnapshot.docs.map((e) => Gonderiler.fromDocument(e)).toList();
setState(() {
  this.tEdilenGonderiler = kullanicires;
});
}


return Scaffold(
  backgroundColor: Colors.white,
  appBar: baslik(context, strBaslik: "Kartlar", geriButonuYokSay: true),
  body: RefreshIndicator(
      color: Colors.black,
      child: ListView(
        children: tEdilenGonderiler,
      ),
      onRefresh: () {
        return tumGonderiler();
      }),
);

推荐阅读