FieldValue.arrayUnion constructor

const FieldValue.arrayUnion(
  1. List<Object?> elements
)

Returns a special value that can be used with set(), create() or update() that tells the server to union the given elements with any array value that already exists on the server. Each specified element that doesn't already exist in the array will be added to the end. If the field being modified is not already an array it will be overwritten with an array containing exactly the specified elements.

final documentRef = firestore.doc('col/doc');

documentRef.update({
  'array': Firestore.FieldValue.arrayUnion('foo'),
}).then(() {
  return documentRef.get();
}).then((doc) {
  // doc.get('array') contains field 'foo'
});

Implementation

const factory FieldValue.arrayUnion(List<Object?> elements) =
    _ArrayUnionTransform;