update method

void update(
  1. DocumentReference documentRef,
  2. Map<Object?, Object?> data, {
  3. Precondition? precondition,
})

Updates fields in the document referred to by the provided DocumentReference. If the document doesn't yet exist, the update fails and returns FirestoreClientErrorCode.notFound.

The update() method accepts either an object with field paths encoded as keys and field values encoded as values, or a variable number of arguments that alternate between field paths and field values.

A Precondition restricting this update.

Implementation

void update(
  DocumentReference<dynamic> documentRef,
  Map<Object?, Object?> data, {
  Precondition? precondition,
}) {
  if (_writeBatch == null) {
    throw Exception(readOnlyWriteErrorMsg);
  }

  _writeBatch.update(
    documentRef,
    {
      for (final entry in data.entries)
        FieldPath.from(entry.key): entry.value,
    },
    precondition: precondition,
  );
}