flutter - Flutter 应用程序错误 - 类型“时间戳”不是“日期时间”类型的子类型
问题描述
我正在获取数据云 Firestore 并尝试使用以下代码在我的应用程序中显示。
new Text(timeago.format(document.data['tripDoc']['docCreatedOn'])),
我正在使用timeago
dart 包来格式化它。但是,在更新到最新的 cloud 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()))
希望,它会帮助某人。
推荐阅读
- java - 从pdf文件中提取具有文本的文本和图像
- vue.js - 未配置 Visual Studio Code 自动格式化程序
- javascript - 使用 webdriver.io 模块获取当前 URL
- amazon-web-services - DynamoDB - 创建表 - IAM 策略 - 未授权错误
- java - HttpsURLConnection 提供连接超时,但使用 JS XMLHttpRequest()
- naming-conventions - 验证用户或验证电话号码?哪个更有意义、更好和更标准?为什么?
- java - 处理按钮区域中手指的进出
- blob - 如何使用 azure 函数中的元数据将 blob 文档从一个容器移动到另一个容器?
- antd - 在同一个项目中使用 antd(React) 和 antd-mobile(React)
- python-3.x - 这些陈述之间有什么区别?