firebase - 我的时间戳没有启用,它显示是错误的
问题描述
我只想使用 timeago 包,为此我试图通过编写以下代码来启用时间戳,但它在编写时显示错误(下面的红线)。另外我正在使用 timeago:^2.0.26 和 cloud_firestore:^0.13 .7.
void main() {
Firestore.instance.settings(timestampsInSnapshotsEnabled: true).then((_) {
print("Timestamps enabled in snapshots\n");
}, onError: (_) {
print("Error enabling timestamps in snapshots\n");
});
runApp(MyApp());
}
解决方案
Firestore.instance.settings(timestampsInSnapshotsEnabled: true).then((_)
这种启用时间戳的方式现在已被弃用,并且不需要该参数,因为默认情况下启用了时间戳。
但是您必须明确告诉程序您正在等待一些数据或在主函数中运行异步函数。代码如下:
WidgetsFlutterBinding.ensureInitialized();
所以整个代码看起来像这样
void main() {
WidgetsFlutterBinding.ensureInitialized(); //The reason behind this is I am waiting for some data or running an async function inside main().
Firestore.instance.settings().then((_) {
print("Timestamps enabled in snapshots\n");
}, onError: (_) {
print("there was an error enabling timestams in snapshots");
});
runApp(MyApp());
}
推荐阅读
- java - 在 android studio 的应用购买中设置问题
- certificate-pinning - 证书固定和转换 isrg-root 让我们加密
- javascript - chart.js - 轴选项问题 - 我做错了什么?
- android - 浮动操作按钮不改变布局
- mongodb - Mongo 在集合中的某个索引处获取 10 个文档
- powershell - 跨会话的Powershell作业?
- reactjs - 身份验证 HOC
- node.js - 使用 Webpack 捆绑 Sqlite3 导致编译错误
- javascript - 当您可以选择没有它的元素时,document.getElementById 有什么意义?
- google-sheets - 数组公式,用于根据单元格的匹配条件与表格中的关联值计算范围平均值