首页 > 解决方案 > 我想添加对象在firebase中具有对象列表,颤振

问题描述

我有对象“律师”有对象列表“制造商”

class Lawer{   

   final int x1;
   final int x2;
   final int x3;
   final List<Maker>objects
  Lawer({this.x1,this.x2,this.x3 ,this.objects});

  Map<String, dynamic> toJson() =>
      {
        'x1':1 ,
        'x2':1,
        'x3':2,     
      };
}
class Maker{
  final String lawerID;
  final String customerID;
  final bool connect;
  Maker({this.lawerID,this.customerID,this.connect=false});
  Map<String, dynamic> toJson() =>
      {
   'lawerID':lawerID,
   'customerID':customerID,
   'connect':connect,
      };
}
CollectionReference dPReplies=FirebaseFirestore.instance.collection('lawers');     FirebaseFirestore.instance.runTransaction((Transaction tx)async {
    var result=await dPReplies.add(lawer.toJson())
 });

如何在firebase中保存这个对象“保存对象有一些变量和对象列表”

标签: firebasefluttergoogle-cloud-firestore

解决方案


  1. 在你的课堂上改变这个:

    Map<String, dynamic> toJson() =>
       {
         'x1':x1,
         'x2':x2,
         'x3':x3,     
       };
    
  2. 你需要大写Lawer

    var result= await dPReplies.add(Lawer.toJson()) //instead of lawer.toJson
    

推荐阅读