问题
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