gpt4 book ai didi

firebase - Flutter/Dart 应用因 Firebase Date 对象的更改而中断

转载 作者:IT王子 更新时间:2023-10-29 06:44:13 26 4
gpt4 key购买 nike

我的代码:

void createCloudStoreRecord(FirebaseUser user) {
// Create/Update user record with uid

final DocumentReference docRefUsers = Firestore.instance.collection("users").document(user.uid);

docRefUsers.get().then((datasnapshot) {
if (datasnapshot.exists) {
// Exists, so do nothing
} else {
// Does not exist, let's create
Map<String, String> data = <String, String> {
"email": user.email,
"photoURL": user.photoUrl,
};
// Save data
docRefUsers.setData(data).whenComplete(() {

}).catchError((e) => print(e));
}
});

错误:

5.0.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. or 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 do not follow these steps, YOUR APP MAY BREAK.

问题是:我只是在创造一个新记录;我根本没有使用任何日期对象。我可以安全地忽略此警告吗?

最佳答案

忽略是安全的,尽管 with v0.8.2或 Firebase 插件,您可以使用以下设置避免警告:

await firestore.settings(timestampsInSnapshotsEnabled: true);

关于firebase - Flutter/Dart 应用因 Firebase Date 对象的更改而中断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50639853/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com