是否可以在查询中使用循环?
Future<void> addServiceConfig(String uid, List<ServiceConfigModel> model) {
_db.collection('users').document(uid).updateData({
'businessDetails':{
'serviceConfig':FieldValue.arrayUnion([
{
for(int i = 0;i <model.length;i++){
if (model[i].inShop != null) 'inShop': model[i].inShop,
if (model[i].inShopAndClientLocation != null)
'inShopAndClientLocation': model[i].inShopAndClientLocation,
if (model[i].clientLocation != null)
'clientLocation': model[i].clientLocation,
'serviceLocations': model[i].serviceLocations,
'subCategoryId': model[i].subCategoryId
}
}
])
}
});
}
我收到此错误:
[ERROR:flutter / lib / ui / ui_dart_state.cc(148)]未处理的异常:无效的参数:'_CompactLinkedHashSet>的实例
答案 0 :(得分:1)
您不能在表达式内使用循环(或许多其他语句),例如字段的值。一种解决方案是将构造值拉到rand()
之外,然后传递给它:
update()
var result = new List();
//var config = new Map()