Flutter Flatter/Google Firestore StreamBuilder未更新数据库
我的StreamBuilder有问题。 在本例中,我有一个带有3个StreamBuilder的TabBarView(用三个选项卡中的一个来编写本文)。从数据库中删除某些内容时,生成器显示错误的数据。有时该项目仍然存在,有时它会加倍。我试图从查询中删除两个orderBy语句。我重新加载了,数据是正确的。在再次添加语句并重新加载后,一切正常 为什么会这样?是因为orderBy语句吗 谢谢Flutter Flatter/Google Firestore StreamBuilder未更新数据库,flutter,google-cloud-firestore,Flutter,Google Cloud Firestore,我的StreamBuilder有问题。 在本例中,我有一个带有3个StreamBuilder的TabBarView(用三个选项卡中的一个来编写本文)。从数据库中删除某些内容时,生成器显示错误的数据。有时该项目仍然存在,有时它会加倍。我试图从查询中删除两个orderBy语句。我重新加载了,数据是正确的。在再次添加语句并重新加载后,一切正常 为什么会这样?是因为orderBy语句吗 谢谢 StreamBuilder( stream: Firestore.instance
StreamBuilder(
stream: Firestore.instance
.collection("bookings")
.document(localUser.centerName)
.collection("center_bookings")
.where("customerId", isEqualTo: localUser.userId)
.orderBy("bookedMonth", descending: false)
.orderBy("bookedDay", descending: false)
.snapshots(),
builder: (BuildContext context,
AsyncSnapshot<QuerySnapshot> snapshot) {
if (snapshot.hasError) {
return Text("Error: ${snapshot.error}");
}
switch (snapshot.connectionState) {
case ConnectionState.waiting:
return Center(
child: CircularProgressIndicator(
backgroundColor: Theme.of(context).primaryColor,
),
);
default:
return Container(
margin: const EdgeInsets.symmetric(
horizontal: 5.0, vertical: 10.0),
child: ListView(
children: snapshot.data.documents.map((document) {
if (_datesNext7Days.contains(document["bookedFor"])) {
return Padding(...);
} else {
return SizedBox();
}
}).toList()),
);
}
},
),
StreamBuilder(
流:Firestore.instance
.收款(“预订”)
.document(localUser.centerName)
.集合(“中心预订”)
.where(“customerId”,isEqualTo:localUser.userId)
.orderBy(“bookedMonth”,降序:false)
.orderBy(“bookedDay”,降序:false)
.snapshots(),
生成器:(BuildContext上下文,
异步快照(快照){
if(snapshot.hasError){
返回文本(“错误:${snapshot.Error}”);
}
交换机(快照.连接状态){
案例连接状态。正在等待:
返回中心(
子对象:循环压缩机指示器(
背景色:主题。背景色,
),
);
违约:
返回容器(
边距:常量边集。对称(
水平:5.0,垂直:10.0),
子:ListView(
子项:snapshot.data.documents.map((文档){
如果(_datesNext7Days.contains(文档[“bookedFor”])){
返回填充(…);
}否则{
返回SizedBox();
}
}).toList()),
);
}
},
),
尝试为streambuilder中的连续数据流返回yeild Your数据类型
下面是示例,不要忘记异步中的*
static Stream<List<MeetingItem>> getMeetingsList() async* {
Firestore fireStore = Firestore.instance;
try {
var collectionsMeeting = fireStore.collection(VConstants.KEYS.meetings);
var snapshots = collectionsMeeting.snapshots();
await for (QuerySnapshot snap in snapshots) {
List<MeetingItem> meetingList = [];
snap.documents.forEach((element) {
meetingList.add(MeetingItem(element.documentID, element.data));
});
yield meetingList;
}
} catch (e) {
print(e);
}
}
}
StreamBuilder(
stream: getMeetingsList()//customize it with your return value