Flutter 应用程序错误 - “Timestamp"类型不是“DateTime"类型的子类型 [英] Flutter app error - type 'Timestamp' is not a subtype of type 'DateTime'

查看:19
本文介绍了Flutter 应用程序错误 - “Timestamp"类型不是“DateTime"类型的子类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在获取数据云 Firestore &尝试使用以下代码在我的应用中显示.

I'm fetching data cloud firestore & trying to show in my app by using the following piece of code.

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

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

I'm using timeago dart package to format that. But, after making updating to latest cloud firestore plugin I'm getting this error -

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

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

Can't able to understand how to parse this 'TimeStamp' object to 'DateTime'. Because timeago plugin need data in DateTime object format.

推荐答案

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

.toDate() worked for me. Now the modified code is -

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

希望对某人有所帮助.

这篇关于Flutter 应用程序错误 - “Timestamp"类型不是“DateTime"类型的子类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆