新的。我已经用Google搜索了所有内容,无法解决。 下面的前两个函数可以正常工作,第三个函数总是立即返回null而不调用我的ListFromSnapShot函数,该函数只是将地图转换为列表。我假设
我没有正确调用Firestore,但不知道如何正确执行此操作。
final CollectionReference customerCollection = Firestore.instance.collection('customers');
final CollectionReference jobCollection = Firestore.instance.collection('jobs');
// get user doc stream
Stream<UserData> get userData {
return customerCollection.document(uid).snapshots()
.map(_userDataFromSnapshot);
}
//Returns only snapshots with matching customer name to StreamProvider object
Stream<List<Job>> get jobQuery {
return jobCollection.where('customerName', isEqualTo: currentCustomer.companyName)
.snapshots()
.map(_jobListFromSnapshot);
}
//The following always returns Null
Stream<List<JobSectionModel>> get jobQuerySections {
return jobCollection.document('Family Dollar').collection('sections')
.snapshots()
.map(_jobSectionListFromSnapshot);
任何帮助将不胜感激。
答案 0 :(得分:2)
上面的代码确实起作用了,但经过几天令人沮丧的问题,该问题最终成为了Firestore路径中的随机空间。我将其发布为答案,因为在进行了谷歌搜索之后,还有许多其他人也遇到了类似的问题,我不希望他们经历同样的挫折。 Firestore不会显示此内容,除非您从字面上单击路径名,并且它不会使程序崩溃,它只会返回任何内容。
帮自己一个忙,添加数据时请使用.trim()函数,如果在Firestore上手动进行操作,请确保没有尾随空格。
我还重新构建了如下代码(当然也没有空格)
Stream<QuerySnapshot> getjobQuerySections(BuildContext context) async*{
yield* jobCollection.document('T-MOBILE').collection('whyspaces').snapshots();
希望这对某人有帮助。祝你好运