Flutter中的Firestore数组大小



如何获取firestore中处于抖动状态的元素数量?

我尝试了.length,但它没有工作。

我正在使用StreamBuilder从firestore获取数据

FirebaseFirestore.instance.collection('list').doc(idof).snapshots()

idof是一个传递的变量,它是文档ID

var userDocument = snapshot.data;
return new Text(userDocument["items"]["0"][0].toString());

项是一个Map "0"是数组名

My Datastore is like

items(Maptype)
0(ArrayName)
0:"Abc"
1:"Efg"

现在只能显示第0个索引Abc

我想要得到数组

中的所有元素
var userDocument = snapshot.data;

如果你想获得文档中元素的个数,那么

int length=userDocument.data.length;

如果你想获得数组'items'的长度

int arrayLength=userDocument['items'].length;

如果你想获得整个数组,那么

List<String> items=List.from(userDocument['items']);

最新更新