dart – Flutter app error – 类型’Timestamp’不是’DateTime’类型的子类型

前端之家收集整理的这篇文章主要介绍了dart – Flutter app error – 类型’Timestamp’不是’DateTime’类型的子类型前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在获取数据云firestore&试图通过使用以下代码在我的应用程序中显示.

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

我正在使用timeago dart包来格式化.但是,在更新到最新的云firestore插件后,我收到此错误

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

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

解决方法

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

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

希望,它会帮助某人.

猜你在找的Flutter相关文章