jjzjj

firebase-realtime-database - flutter Firebase 电线操作

coder 2023-07-22 原文

这是我在 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;
          });
}

但是返回错误

Invalid argument: Instance of 'Address'

我哪里做错了?

最佳答案

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;
          });
}

关于firebase-realtime-database - flutter Firebase 电线操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54050861/

有关firebase-realtime-database - flutter Firebase 电线操作的更多相关文章

随机推荐