简体   繁体   English

从 firestore 子集合检索快照到 dart/flutter 对象

[英]Retrieving snapshots from firestore sub-collection to dart/flutter object

New here.新来的。 I've googled everything and can't figure this out.我已经用谷歌搜索了一切,无法弄清楚这一点。 The first two functions below work flawlessly the third always return null immediately without calling my ListFromSnapShot function, which just turns the map into a list.下面的前两个函数可以完美地工作,第三个函数总是立即返回 null 而不调用我的 ListFromSnapShot 函数,它只是将地图转换为列表。 I am assuming我假设

I'm not calling the Firestore correctly but I have no idea how to do this properly.我没有正确调用 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); 

This is my database structure Base Collection这是我的数据库结构 Base Collection 基础系列

Subcollection子集子集

Any help would be greatly appreciated.任何帮助将不胜感激。

The code above does work, the problem, after several frustrating days, ended up being random spaces in the firestore path.上面的代码确实有效,问题在令人沮丧的几天后最终成为 firestore 路径中的随机空间。 I'm posting this as an answer because after googling this there were many others with a similar problem and I don't want them to go through the same frustration.我将此作为答案发布,因为在谷歌搜索之后,还有许多其他人遇到了类似的问题,我不希望他们经历同样的挫折。 Firestore will not show this until you literally click on the path name and it will not crash your program, it just returns nothing. Firestore 不会显示这个,直到你直接点击路径名,它不会让你的程序崩溃,它只是什么都不返回。

Do yourself a favor and use the .trim() function when adding data and if you do it manually on firestore make sure there's no trailing spaces.帮自己一个忙,在添加数据时使用 .trim() 函数,如果您在 firestore 上手动执行此操作,请确保没有尾随空格。

Also I rebuilt the code as follows which also works (without spaces of course)我也重新构建了如下代码,它也可以工作(当然没有空格)

Stream<QuerySnapshot> getjobQuerySections(BuildContext context) async*{

  yield* jobCollection.document('T-MOBILE').collection('whyspaces').snapshots();

Hope this helps someone.希望这可以帮助某人。 Good Luck祝你好运

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM