flutter - 从 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();
});
}
解决方案
我已经稍微更改了我的代码,直到现在它正在工作,你可以从下面跟随
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();
}),
);
推荐阅读
- docker - 主机上的 Docker 新用户,如何让 docker 知道?
- python - 无效的语法 (
,第 4 行)(语法错误) - php - 如何在 smarty 中使用 regex_replace?
- java - 在 Android Studio 中:如何更新列数据?
- rust - Rust 模式匹配如何确定绑定变量是引用还是值?
- bash - 如何监控特定单词的 IPMI SOL 输出,然后回显一个短语?
- c - 如何在 C 中完全重新分配二维数组?
- javascript - 是否有替代 console.log() 的方法,它可以让您打印并更新一行而不是向控制台发送垃圾邮件?
- python - 包安装在 anaconda\lib\site-packages 并在 spyder 中找到,但不在 jupyter 笔记本中
- c# - 如何在后台运行代码时将数据提供给 div 标签