Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Firebase 具有动态路径的Firestore CollectionReference不';行不通_Firebase_Flutter_Dart_Google Cloud Firestore - Fatal编程技术网

Firebase 具有动态路径的Firestore CollectionReference不';行不通

Firebase 具有动态路径的Firestore CollectionReference不';行不通,firebase,flutter,dart,google-cloud-firestore,Firebase,Flutter,Dart,Google Cloud Firestore,我试图用一个动态路径(特定于用户)查询firestore集合,它是硬编码的,但不使用变量进行动态查询,有人知道这个问题并能提供帮助吗 提前谢谢 final CollectionReference addressCollection = Firestore.instance.collection('users/r9qClctByGXinYAmB2MqQNctgd53/addresses'); 工作 这不是: final CollectionReference addressCollection

我试图用一个动态路径(特定于用户)查询firestore集合,它是硬编码的,但不使用变量进行动态查询,有人知道这个问题并能提供帮助吗

提前谢谢

final CollectionReference addressCollection =
 Firestore.instance.collection('users/r9qClctByGXinYAmB2MqQNctgd53/addresses');
工作

这不是:

final CollectionReference addressCollection =
 Firestore.instance.collection('users/$userId/addresses');
用户ID=R9QCLCTBYGXINAMB2MQNCTGD53

FireStore数据库完整代码:

class FirestoreDatabase {
  final _service = FirestoreService.instance;

  static String userId;

  void setUserId(uid) {
    userId = uid; 
  }

  final CollectionReference addressCollection =
      Firestore.instance.collection('users/$userId/addresses');

// Adresses List Stream

  Stream<List<Address>> get addressesStream {
    return addressCollection.snapshots().map(_addressListFromSnapshot);
  }

  List<Address> _addressListFromSnapshot(QuerySnapshot snapshot) {
    return snapshot.documents.map((doc) {
      return Address.fromMap(doc.data);
    }).toList();
  }
}

类FirestoreDatabase{
final _service=FirestoreService.instance;
静态字符串用户标识;
void setUserId(uid){
userId=uid;
}
最终收集参考地址收集=
Firestore.instance.collection('users/$userId/addresses');
//地址列表流
流获取地址流{
返回addressCollection.snapshots().map(\u addressListFromSnapshot);
}
列表_addressListFromSnapshot(QuerySnapshot快照){
返回snapshot.documents.map((doc){
返回地址.fromMap(文档数据);
}).toList();
}
}

你想要一个特定的
r9qclctbygxinamb2mqqnctgd53
或任何id?对于一个特定的id,你说即使
$userId
持有
r9qclctbygxinamb2mqnctgd53
的值,它在你的路径中也无法识别?它在路径中被识别(我还使用一个函数构建了整个路径,并将其放入CollectionReference中)。我还获得了一个快照,但使用空的MAPI如果您解决了自己的问题,那么也可以自由回答您自己的问题。