flutter - 将方法移动到流构建器
问题描述
List<Photo> imgList = [];
Future getCarouselWidget() async {
var firestore = Firestore.instance;
QuerySnapshot qn =
await firestore.collection("history").getDocuments();
List pics = qn.documents
.map((it) => Photo(it['photo'].toString(), it['name'].toString(), it['address'].toString()))
.toList();
return imgList = pics;
}
大家好,当我在我的数据库中进行更改时,我在我的应用程序中看不到它们?任何人都可以帮助我或指导我如何将其连接到流构建器或查询流
StreamBuilder<QuerySnapshot>(
stream: Firestore.instance
.collection('swimfinderlakes')
.snapshots(),
builder: (context, snapshot) {
解决方案
每次 Firestore 发生变化时,都会触发StreamBuilder
. snapshot
然后,您可以使用onbuilder
方法访问最近的更新。然后您可以使用它来相应地更新用户界面。
StreamBuilder<QuerySnapshot>(
stream: Firestore.instance
.collection('swimfinderlakes')
.snapshots(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.active) {
if (snapshot.hasData) {
List pics = qn.documents
.map((it) => Photo(it['photo'].toString(),
it['name'].toString(), it['address'].toString())).toList();
return pics;
}
} else {
return CircularProgressIndicator();
}
}
推荐阅读
- jquery - 在本地服务器上使用 Flask 和 Gunicorn 构建的 API 不使用 jQuery 响应客户端的请求,但响应 Postman
- java - 将字符串值从没有构建器的活动发送到正常活动
- html - html+css布局问题(定位项)
- jquery - 执行多个 XHR 请求,无需相互等待
- sas - 将 ods 的 sas 输出导出到乳胶的问题(背面
- ember.js - 错误:您试图覆盖内置帮助程序“数组”。这是从哪里来的?
- c++ - 为什么两者都有 std::move
和 - uitableview - 部分标题视图中的 UIPanGestureRecognizer 影响 UITableViewCell
- python - 使用cdf函数计算(≤2)=(0)+(1)+(2)
- sql-server - SSIS - 目标excel不显示所有单元格,而只显示F1,F2等