commit method

Future<List<WriteResult>> commit()

Atomically commits all pending operations to the database and verifies all preconditions. Fails the entire write if any precondition is not met.

Returns a future that resolves when this batch completes.

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

writeBatch.set(documentRef, {foo: 'bar'});

writeBatch.commit().then(() {
  console.log('Successfully executed batch.');
});

Implementation

Future<List<WriteResult>> commit() async {
  final response = await _commit(transactionId: null);

  return [
    for (final writeResult
        in response.writeResults ?? <firestore1.WriteResult>[])
      WriteResult._(
        Timestamp._fromString(
          writeResult.updateTime ?? response.commitTime!,
        ),
      ),
  ];
}