这是我的代码,用于在Firebase实时数据库中添加新地址
Future<bool> addAddress(Address adr)async{
database = FirebaseDatabase(app: app);
await database
.reference()
.child(table_name).child(uid)
.set(adr).then((onValue){
print("adress add complected");
return true;
}).catchError((onError){
print("adress add failed $uid");
print(onError);
return false;
});
}
但返回错误
无效的参数:“地址”的实例
我在哪里错地方?
答案 0 :(得分:1)
您对set()的输入必须为Map类型,因此您必须执行以下操作:
Future<bool> addAddress(Address adr)async{
database = FirebaseDatabase(app: app);
await database
.reference()
.child(table_name).child(uid)
.set({
"country": adr.count,
"state": adr.state,
"city": adr.city,
}).then((onValue){
print("adress add complected");
return true;
}).catchError((onError){
print("adress add failed $uid");
print(onError);
return false;
});
}