gpt4 book ai didi

firebase - Flutter cloud_firestore 系统日期对象的设置/警告

转载 作者:IT老高 更新时间:2023-10-28 12:42:21 27 4
gpt4 key购买 nike

在使用 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 实现中传递?

最佳答案

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

https://github.com/flutter/flutter/issues/18159#issuecomment-431176341

这样做是这样的:

await firestore.settings(timestampsInSnapshotsEnabled: true);

关于firebase - Flutter cloud_firestore 系统日期对象的设置/警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50510396/

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