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获取文档id_Firebase_Flutter_Dart_Google Cloud Firestore - Fatal编程技术网

Firebase 如何从firestore获取文档id

Firebase 如何从firestore获取文档id,firebase,flutter,dart,google-cloud-firestore,Firebase,Flutter,Dart,Google Cloud Firestore,我正试图在我的收藏“meinprofilsettings”中获取我的每个文档id。但我有点挣扎,所以也许任何人都能帮上忙 首先,这是我的代码: List<String> alluserids = []; getHashtags() async { final ref = FirebaseFirestore.instance; QuerySnapshot snapshots = await ref.collection('meinprofilsettings').g

我正试图在我的收藏“meinprofilsettings”中获取我的每个文档id。但我有点挣扎,所以也许任何人都能帮上忙

首先,这是我的代码:

List<String> alluserids = [];

getHashtags() async {
    final ref = FirebaseFirestore.instance;

    QuerySnapshot snapshots = await ref.collection('meinprofilsettings').get();

    for (QueryDocumentSnapshot idofuser in snapshots.docs) {
      allVideoHastags.addAll(idofuser.id);
    }
}
List alluserids=[];
getHashtags()异步{
final ref=FirebaseFirestore.instance;
QuerySnapshot snapshot=await ref.collection('meinprofilsettings').get();
for(snapshots.docs中的QueryDocumentSnapshot idofuser){
allVideoHastags.addAll(idofuser.id);
}
}
下面是我得到的错误:

无法将参数类型“String”分配给参数类型“Iterable”

这是我的数据库的屏幕截图:


我只需要列表AllUserID中每个文档的每个id。

addAll方法接收一个Iterable作为参数。您希望添加单个值,因此应使用
。添加

此外,您还可以使用.map方法代替中的for:

allVideoHastags.addAll(snapshots.docs.map((idofuser)=>idofuser.id));
最后一条语句背后的行为是,map返回一个
Iterable
,该值对应于基本
Iterable
(在本例中为您的文档)包含的每个值


在本例中,基本iterable是
快照。docs
,当我们返回每个doc id时,我们的映射将返回
iterable
。希望这足以帮助您更改它

allVideoHastags.addAll(idofuser.id);
为此:

alluserids.add(idofuser.id);

好的,我如何检查一个字符串是否存在于where中?我是使用araycontains还是isEqualTo,或者我应该使用什么?你想检查一下吗?不,我的意思是,比如当我使用这样的东西时。我应该使用araycontains还是isEqualTo,或者我需要什么?对不起,我不明白。您可以创建一个新问题,以便更好地解释它