Firebase 系统日期对象的Flatter cloud\u firestore设置/警告

Firebase 系统日期对象的Flatter cloud\u firestore设置/警告,firebase,dart,google-cloud-firestore,flutter,Firebase,Dart,Google Cloud Firestore,Flutter,在使用cloud_firestore访问cloud firestore文档数据库的Flatter应用程序中,调试时控制台中出现以下警告/错误 4.13.0 - [Firebase/Firestore][I-FST000001] The behavior for system Date objects stored in Firestore is going to change AND YOUR APP MAY BREAK. To hide this warning and ensure your

在使用cloud_firestore访问cloud firestore文档数据库的Flatter应用程序中,调试时控制台中出现以下警告/错误

4.13.0 - [Firebase/Firestore][I-FST000001] The behavior for system Date objects stored in Firestore is going to change AND YOUR APP MAY BREAK.
To hide this warning and ensure your app does not break, you need to add the following code to your app before calling any other Cloud Firestore methods:

let db = Firestore.firestore()
let settings = db.settings
settings.areTimestampsInSnapshotsEnabled = true
db.settings = settings

With this change, timestamps stored in Cloud Firestore will be read back as Firebase Timestamp objects instead of as system Date objects. So you will also need to update code expecting a Date to instead expect a Timestamp. For example:

// old:
let date: Date = documentSnapshot.get("created_at") as! Date
// new:
let timestamp: Timestamp = documentSnapshot.get("created_at") as! Timestamp
let date: Date = timestamp.dateValue()

Please audit all existing usages of Date when you enable the new behavior. In a future release, the behavior will be changed to the new behavior, so if you d<…>
但是我没有看到这里暴露的设置对象


是否有人知道这些设置是否可以在不同的地方进行配置,或者在cloud\u firestore的Flatter/Dart实现中还没有通过此功能?

您可以从Firebase插件的v0.8.2开始设置:

是这样做的:

await firestore.settings(timestampsInSnapshotsEnabled: true);

我发布了一个答案,但被版主删除了,因为它与另一个问题的答案相同。显然这是不允许的(!!!)。也许我可以在这里发布一条有帮助的评论和链接?
await firestore.settings(timestampsInSnapshotsEnabled: true);