首页 文章

飘散cloud_firestore系统日期对象的设置/警告

提问于
浏览
4

在使用cloud_firestore访问Cloud Firestore文档数据库的Flutter应用程序中,我在调试时在控制台中收到以下警告/错误...

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<…>

我试图确定如何在Flutter cloud_firestore包(包装本机包)中进行这些设置/配置更改 .

我在主应用程序启动时静态加载firestore对象,并将其添加到在整个应用程序中持久存在的redux中间件包 . 所以我想我会添加像这样的静态函数...

static Firestore getStartupFirestore() {
    var fs = Firestore.instance;

// #TODO: adapt this code to Dart for Flutter implementation
// let db = Firestore.firestore()
// let settings = db.settings
// settings.areTimestampsInSnapshotsEnabled = true
// db.settings = settings

    return fs;
  }

但我没有看到这里公开的设置对象 .

有没有人知道是否有可以配置这些设置的不同位置,或者是否在cloud_firestore的Flutter / Dart实现中尚未传递此功能?

1 回答

相关问题