首页 > 解决方案 > Flutter 应用程序错误 - 类型“时间戳”不是“日期时间”类型的子类型

问题描述

我正在获取数据云 Firestore 并尝试使用以下代码在我的应用程序中显示。

new Text(timeago.format(document.data['tripDoc']['docCreatedOn'])),

我正在使用timeagodart 包来格式化它。但是,在更新到最新的 cloud firestore 插件后,我收到了这个错误 -

Another exception was thrown: type 'Timestamp' is not a subtype of type 'DateTime'

无法理解如何将此“TimeStamp”对象解析为“DateTime”。因为timeago插件需要 DateTime 对象格式的数据。

标签: flutterdartgoogle-cloud-firestore

解决方案


.toDate()为我工作。现在修改后的代码是 -

new Text(timeago.format(document.data['tripDoc']['docCreatedOn'].toDate()))

希望,它会帮助某人。


推荐阅读