update method
Updates the fields in data of the existing document documentRef when
the transaction commits. Fields that are not in data keep their
values.
The keys of data are field paths, a String or a FieldPath:
'address.city' changes only city
inside the map address. A converter of documentRef is not used.
transaction.update(firestore.doc('cities/SF'), <String, Object?>{
'population': FieldValue.increment(1),
});
The document must exist. If the transaction read it and it was missing, the commit fails with FirestoreErrorCode.invalidArgument; if the transaction did not read it and it is missing, the commit fails with FirestoreErrorCode.notFound. Neither is retried.
Throws an ArgumentError if data holds an invalid field path or value,
or if documentRef belongs to another FirebaseFirestore instance. Throws a
FirestoreException with FirestoreErrorCode.invalidArgument in a
read-only transaction.
Returns this transaction, so that calls can be chained.
Implementation
Transaction update(
DocumentReference<Object?> documentRef,
Map<Object, Object?> data,
) {
final UserDataParsedUpdateData parsedData = _firestore.dataConverter
.parseUpdateMap(
data,
methodName: 'Transaction.update',
targetDoc: documentRef.key,
);
return _update(documentRef, parsedData);
}