【发布时间】:2021-08-23 08:33:16
【问题描述】:
我正在尝试从集合中获取文档列表,但出现超出范围的错误。您可以看到返回列表的函数以及之后的输出。
Future<List> getPreAppliedUserList() async {
try {
List? userList = [""];
QuerySnapshot querySnapshot =
await _db!.collection(_preAppliedUserCollection).get();
List allData = querySnapshot.docs.map((doc) => doc.data()).toList();
print(allData.length); /// 2
for (int i = 0; i <= allData.length; i++) {
userList[i] = await allData[i]['customerNumber'];
}
return userList;
} on FirebaseException {
print("getPreAppliedUserList error");
var x; ///todo
return x;
}
}
错误:
Error: RangeError (index): Index out of range: index should be less than 1: 1
【问题讨论】:
标签: javascript firebase flutter dart