flutter firestore, add new object in array

。_饼干妹妹 提交于 2020-03-16 02:01:28

问题


I have array of objects, I want to add new object when user enter new data in the array?

Firestore.instance.collection(city).document('Attractions').updateData(
                        "data", FieldValue.arrayUnion(obj)
                      );

This shows error, How can I achieve this with flutter?


回答1:


Right Format is :

Firestore.instance.collection(city).document('Attractions').updateData({"data": FieldValue.arrayUnion(obj)});

updateData Take Map<String,dynamic> as data.

In your Code you are having , as separator between key - value instead it should be :




回答2:


@anmol.majhail 's is right, but to solve @Sami Ullah's problem, you must first make a list and add the object into the list like this:

var list = List<ObjectType>();
list.add(obj);
Firestore.instance.collection('city').document('Attractions').updateData({"data": FieldValue.arrayUnion(obj)});



来源:https://stackoverflow.com/questions/53665155/flutter-firestore-add-new-object-in-array

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!