我想和消防站保持一段距离
共有93个文件
因此此功能需要几分钟来浏览所有文档
这是我的计算代码-
int length;
DateTime earlyTime;
DateTime lateTime;
String name;
String finalName;
QuerySnapshot snaps =
await Firestore.instance.collection('nameDetails').getDocuments();
List<DocumentSnapshot> snapCount = snaps.documents;
length = snapCount.length;
// Count of Documents in Collection
for (int count = 1; count < length; count++) {
print(count);
await Firestore.instance
.collection('nameDetails')
.document(count.toString())
.get()
.then(
(time) {
//Parsing the strings into DateTime
earlyTime = DateTime.parse(time['beforeTime']);
lateTime = DateTime.parse(time['afterTime']);
name = time['name'];
print(name);
},
);
if (birthDayTime.isAfter(earlyTime) && birthDayTime.isBefore(lateTime)) {
name = finalName;
break;
}
}
}
那么,有什么有效的方法可以做到这一点吗?
如果有人可以帮助我,那就太好了:)
最佳答案
您正在检索nameDetails
集合内的文档两次,而这并不是真正需要的。如果只想获取距离,则可以执行以下操作:
QuerySnapshot snaps =
await Firestore.instance.collection('nameDetails').getDocuments();
for (var docs in snaps.documents) {
earlyTime = DateTime.parse(docs['beforeTime']);
lateTime = DateTime.parse(docs['afterTime']);
name = docs['name'];
print(name);
if (birthDayTime.isAfter(earlyTime) &&
birthDayTime.isBefore(lateTime)) {
name = finalName;
break;
}
}
关于firebase - 如何获得从消防站到 flutter 的时间距离,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61453373/