Flutter 如何将FieldValue类型的serverstamp添加到现有的类型映射<;字符串,动态>;
我有一个方法,应该为每个文档集添加一个服务器时间戳Flutter 如何将FieldValue类型的serverstamp添加到现有的类型映射<;字符串,动态>;,flutter,dart,google-cloud-firestore,Flutter,Dart,Google Cloud Firestore,我有一个方法,应该为每个文档集添加一个服务器时间戳 Future<void> _setDocument(String path, {Map<String, dynamic> inputData}) async { final outputData = {'createdAt':FieldValue.serverTimestamp()}; outputData.addAll(inputData) try { final Documen
Future<void> _setDocument(String path, {Map<String, dynamic> inputData}) async {
final outputData = {'createdAt':FieldValue.serverTimestamp()};
outputData.addAll(inputData)
try {
final DocumentReference documentReference = fireStore.document(path);
return documentReference.setData(outputData);
} on PlatformException catch (error) {
throw UserFriendlyException('Operation Failed', error.message);
}
}
Future\u setDocument(字符串路径,{Map inputData})异步{
final outputData={'createdAt':FieldValue.serverTimestamp()};
outputData.addAll(inputData)
试一试{
final DocumentReference=fireStore.document(路径);
返回documentReference.setData(outputData);
}平台上异常捕获(错误){
抛出UserFriendlyException('操作失败',错误消息);
}
}
但我一直得到以下错误
{Map<String, String> inputData}
The argument type 'Map<String, String>' can't be assigned to the parameter type 'Map<String, FieldValue>'.dartargument_type_not_assignable
'CastMap<String, FieldValue, String, dynamic>' is not a subtype of type 'Map<String, String>' of 'other'
{Map inputData}
无法将参数类型“Map”分配给参数类型“Map”。参数类型不可分配
那么我怎样才能把地图加在一起呢
编辑
即使是铸造似乎也不起作用
final outputData = Map.castFrom<String, FieldValue, String, dynamic>({'createdAt':FieldValue.serverTimestamp()});
outputData.addAll(inputData);
final outputData=Map.castFrom({'createdAt':FieldValue.serverTimestamp()});
outputData.addAll(inputData);
它抛出以下错误
{Map<String, String> inputData}
The argument type 'Map<String, String>' can't be assigned to the parameter type 'Map<String, FieldValue>'.dartargument_type_not_assignable
'CastMap<String, FieldValue, String, dynamic>' is not a subtype of type 'Map<String, String>' of 'other'
'CastMap'不是'other'的'Map'类型的子类型
在不声明类型的情况下,outputData
被推断为映射
相反,您需要声明outputData
最终地图输出数据={
“createdAt”:FieldValue.serverTimestamp(),
};
尝试将outputData
转换为Map
final outputData=Map.castFrom({'createdAt':FieldValue.serverTimestamp()});作品谢谢你的回答,我可以接受吗?哦,nvm,当我尝试合并地图时,它不起作用