How do I add equal elements to an array in Firestore in Flutter?
993
According to the documentation here, array union will only add the elements that are not present. Because you're using a Firestore function intended to only add new unique values, it will behave that way without being bypassed. You can certainly bypass this function, though, but not without first calling the document, retrieving the array, and appending it before updating it to Firestore.
Author by
TheRuedi
Updated on December 13, 2022Comments
-
TheRuedi over 1 year
I just figured out that in Flutter
List<int> values = [1,2,3,1,2,3]; Firestore.instance.path.updateData({"values": FieldValue.arrayUnion(values)});
results in the Firestore Array
(Firestore Array) [1,2,3]
Obviously the values are somehow mapped, removing duplicate values, although I can manually add duplicate values online in the Firebase panel (the datatype is called array respectively).
Is there a way to bypass this behaviour or is this a bug?
-
Hassan Ansari over 4 yearsIt doesn't work, it say "The argument type Set can't be assigned to parameter type 'Map<String, dynamic>' I'm using flutter and my array is List<String>