【发布时间】:2022-02-18 18:36:41
【问题描述】:
我当前的代码使用:
var currentUID = await database.getCurrentUserID();
在这行代码上使用 await 运行此函数会将数据以正确的用户 ID 存储在 Firestore 中,但时间始终设置为 0:
Future<void> addUserTime() async {
var currentUID = await database.getCurrentUserID();
return await database.workoutCollection
.doc(currentUID.toString())
.set({
'Workout Time': format(duration),
})
.then((value) => print('Time added'))
.catchError((error) => print('Failed to add time to database'));
}
不使用 await 像上一行这样的代码:
var currentUID = database.getCurrentUserID();
Firestore 显示:这是 firebase 输出。 Firebase 身份验证的用户 ID 错误,但时间始终设置为用户记录的内容:
Future<void> addUserTime() async {
var currentUID = database.getCurrentUserID();
return await database.workoutCollection
.doc(currentUID.toString())
.set({
'Workout Time': format(duration),
})
.then((value) => print('Time added'))
.catchError((error) => print('Failed to add time to database'));
}
这是我调用getCurrentUserID() 函数的数据库类:
如何获得正确的 UID 和用户登录的正确时间?
【问题讨论】:
标签: firebase flutter dart google-cloud-firestore async-await