Firebase 如何获得从firestore到Flatter的时间距离
我想从firestore获得一个时间距离 共有93份文件 因此,此函数只需几分钟即可浏览所有文档 这是我的计算代码-Firebase 如何获得从firestore到Flatter的时间距离,firebase,datetime,flutter,dart,google-cloud-firestore,Firebase,Datetime,Flutter,Dart,Google Cloud Firestore,我想从firestore获得一个时间距离 共有93份文件 因此,此函数只需几分钟即可浏览所有文档 这是我的计算代码- int length; DateTime earlyTime; DateTime lateTime; String name; String finalName; QuerySnapshot snaps = await Firestore.instance.collection('nameDetails').getDocuments();
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;
}
}
}
int长度;
日期时间早;
日期时间延迟;
字符串名;
字符串最终名称;
QuerySnapshot快照=
等待Firestore.instance.collection('nameDetails').getDocuments();
List snapCount=snaps.documents;
长度=snapCount.length;
//收集中的文件计数
for(int count=1;count
那么,有什么有效的方法可以做到这一点吗?
如果有人能帮助我,那就太好了:)您正在检索集合
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;
}
}
是的,成功了!早些时候,我花了将近一分钟来计算,但现在只花了几秒钟,非常感谢,另外一件事是,在计算过程中,我如何添加加载屏幕?因为我还有一些计算要处理,关于加载,你可以使用循环压缩机指示器来显示加载