在 Flutter 中从 Firebase 实时数据库读取和存储数据

问题描述

我的 firebase rtdb 上有一些对象形式的数据,我只想检索设备上的数据并使用持久性方法保存它。我已经研究了一个月,寻找了很多可能的解决方案,但这似乎没有帮助。 这是我的数据结构:

(如果您需要任何缺失的信息,请告诉我)

enter image description here

提前致谢!

编辑 #1

这是我试过的

class contact{
 final String name,desig,category,ip_direct,ip_office,ip_res,ll_off,ll_res,mob;

 contact({this.name,this.desig,this.category,this.ip_direct,this.ip_office,this.ip_res,this.ll_off,this.ll_res,this.mob});

 factory contact.fromJson(Map<dynamic,dynamic> json){
  return contact(
    name: json["Name"],desig: json["Design"],category: json["Category"],ip_direct: json["IP Direct"].toString(),ip_office: json["IP Office"].toString(),ip_res: json["IP Home"].toString(),ll_off: json["LL Office"].toString(),ll_res: json["LL Home"].toString(),mob: json["Mobile"].toString(),);
 }
}

Future<List<contact>> getList()async{
    final dbRef = FirebaseDatabase.instance.reference().child("Deans");
    List<contact> list=new List();
    DataSnapshot snap=await dbRef.once();
    List<dynamic> obj=snap.value;

    for(int i=0; i<obj.length; i++){
      list.add(contact.fromJson(obj[i]));
    }
    return list;
  }

我无法在这里持久化数据

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)