runBatch method

Future<void> runBatch(
  1. BatchCallback batchFunction
)

Runs batchFunction on a new WriteBatch and then commits the writes it added as a single atomic unit.

The returned future completes when the commit completes (see batch). If batchFunction throws, nothing is committed and the future fails with that error.

await firestore.runBatch((WriteBatch batch) async {
  batch.set(firestore.doc('cities/NYC'), {'name': 'New York City'});
  batch.delete(firestore.doc('cities/LA'));
});

Implementation

Future<void> runBatch(BatchCallback batchFunction) async {
  final WriteBatch batch = this.batch();
  await batchFunction(batch);
  return batch.commit();
}