FbTransaction class

A wrapper for Firestore transactions that provides a simplified interface for performing atomic operations.

Transactions ensure multiple read and write operations are performed atomically, meaning either all operations succeed or all operations fail. This is useful for maintaining data consistency when updating multiple documents.

Example:

await Fb.runTransaction((transaction) async {
  // Read current user data
  final userData = await transaction.get('users/123');
  if (userData == null) throw Exception('User not found');

  // Update user points and create points history
  final currentPoints = userData['points'] as int? ?? 0;
  transaction.update('users/123', {
    'points': currentPoints + 100,
    'updatedAt': FieldValue.serverTimestamp(),
  });

  transaction.set('users/123/history/${DateTime.now().toIso8601String()}', {
    'type': 'points_added',
    'amount': 100,
    'timestamp': FieldValue.serverTimestamp(),
  });

  return currentPoints + 100;
});

Constructors

FbTransaction.create(Transaction _transaction)
Creates a new FbTransaction instance.

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

delete(String path) → void
Deletes a document within the transaction.
get(String path) Future<Map<String, dynamic>?>
Reads a document's data within the transaction.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
set(String path, Map<String, dynamic> data, {bool merge = false}) → void
Sets a document's data within the transaction.
toString() String
A string representation of this object.
inherited
update(String path, Map<String, dynamic> data) → void
Updates specific fields in a document within the transaction.

Operators

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