WriteBatchWithReference<T> class

A container for a Firestore write batch and its most recently used document reference

This class helps track batch operations by keeping both the batch and the last document reference together. This is useful for:

  • Chaining batch operations
  • Accessing the last modified document
  • Maintaining type safety in batch operations
  • Building complex atomic updates

Example:

// Create a new user in a batch
final response = await api.createDocs(
  writeable: user,
  writeBatch: batch,
);

response.when(
  success: (result) async {
    // Access the batch and reference
    final batch = result.writeBatch;
    final userRef = result.documentReference;

    // Add more operations to the batch
    batch.update(userRef, {'status': 'active'});

    // Commit all changes atomically
    await batch.commit();
  },
  fail: (error) => print('Error: $error'),
);

Constructors

WriteBatchWithReference.new({required WriteBatch writeBatch, required DocumentReference<T> documentReference})
Creates a new write batch with reference container
const

Properties

documentReference → DocumentReference<T>
Reference to the last document in the batch
final
hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
writeBatch → WriteBatch
The Firestore write batch for atomic operations
final

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited