我正在尝试获取DateTime.now()并使用Cloud FireStore进行写入/读取。但是得到了错误
这是我的代码
在用户界面中
Text(
DateFormat('dd/MM/yyyy kk:mm')
.format(DateTime
.fromMillisecondsSinceEpoch(int.parse(document[index].data['timeCreated']))),
style: timeStyle,
),
将数据写入Firestore
Firestore.instance.runTransaction((transaction) async {
await transaction.set(
docRef,
{'timeCreated': DateTime.now().millisecondsSinceEpoch.toString()},
);
});
并得到这个错误
I/flutter ( 3378): Another exception was thrown: type 'DateTime' is not a subtype of type 'String'
最佳答案
转换为字符串:
int time = DateTime.now().millisecondsSinceEpoch;
String t = "$time";
关于firebase - 在Flutter Cloud Firestore中, 'DateTime'类型不是 'String'类型的子类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57510760/