Flutter CloudFirestore adding complex types throws

2019-08-21 04:11发布

I have class Match that has a list of other classes of type Team. Upload of new document (Match) to Firestore is only possible if the list is empty. Once there is Team item in the list, attempt to add it to Firestore throws 'Invalid argument: Instance of 'Team''. Team class only contains simple fields, no other classes.

Exception is thrown from StandardMessageCodec.writeValue

Update: I am using cloud_firestore: ^0.8.2, and calling

await firestore.collection('matches').document(match.id).setData(match);

since there is no other method that would allow for upload other than setData (accepting Map), I have tried for match.teams (List):

  1. 'teams' : teams (List)
  2. 'teams' : encode to json completely (String)
  3. 'teams' : encode individual Team items and add to collection (List)

1st option will fail, second will create a single string document member and third will create an array of strings inside member, none of which is what I want - create an array of team objects inside document

1条回答
闹够了就滚
2楼-- · 2019-08-21 04:47

After help from Gunter that pointed to me that such data composition is not supported, I figured it out - List of specific objects needs to be transformed into a List of Map

查看更多
登录 后发表回答