TDocumentService<T extends TWriteableId, API extends TFirestoreApi<T>> class abstract

A service for managing a single Firestore document with synchronized local state.

Extends TAuthSyncService to provide functionality for managing a single document that needs to be synchronized between Firestore and local state. It handles:

  • Local state management with optimistic updates
  • Remote state synchronization
  • Transaction support
  • Error handling
  • Automatic user authentication state sync
  • Before/after update notifications

Type Parameters:

  • T - The document type, must extend TWriteableId
  • API - The Firestore API type, must extend TFirestoreApi
Inheritance
Implementers

Constructors

TDocumentService({required API api})
Creates a new TDocumentService instance.

Properties

afterLocalNotifyUpdate ValueChanged<T?>?
Called after local state is updated.
getter/setter pair
analytics → TAnalytics
Provides the configured TAnalytics functionality through the Turbolytics mixin per type of D.
latefinalinherited
api → API
The Firestore API instance used for remote operations.
final
beforeLocalNotifyUpdate ValueChanged<T?>?
Called before local state is updated.
getter/setter pair
cachedUserId String?
The ID of the currently authenticated user.
getter/setter pairinherited
defaultValueLocator TLocatorDef<T>?
Function to provide default document value.
getter/setter pair
doc ValueListenable<T?>
Value listenable for the document state.
no setter
hashCode int
The hash code for this object.
no setterinherited
id String?
Whether a document exists in local state. The document ID.
no setter
initialValueLocator TLocatorDef<T>?
Function to provide initial document value.
getter/setter pair
isReady Future<void>
Future that completes when the service is ready.
no setter
listenable Listenable
Listenable for the document state.
no setter
location String
Used to define the location of Turbolytics logging and implementation.
no setterinherited
log → TLog
Used to provide all logging capabilities.
latefinalinherited
onAuth FutureOr<void> Function(User user)?
Called when a user is authenticated.
getter/setter pairinherited
onData Future<void> Function(T? value, User? user)
Handles incoming data updates from Firestore.
no setteroverride
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
stream FutureOr<Stream<T?>> Function(User user)
Returns a stream of data for the authenticated user.
no setterinherited

Methods

analyticsAs<A extends TAnalytics>() → A
Provides the configured TAnalytics functionality through the Turbolytics mixin per type of A.
inherited
createDoc({Transaction? transaction, required CreateDocDef<T> doc, bool doNotifyListeners = true}) Future<TurboResponse<T>>
Creates a new document both locally and in Firestore.
createLocalDoc({required CreateDocDef<T> doc, bool doNotifyListeners = true}) → T
Creates a new document in local state.
deleteDoc({required String id, bool doNotifyListeners = true, Transaction? transaction}) Future<TurboResponse<void>>
Deletes a document both locally and from Firestore.
deleteLocalDoc({required String id, bool doNotifyListeners = true}) → void
Deletes a document from local state.
dispose() Future<void>
Disposes of the document service and releases resources.
override
getCustomClaim<T>(String key, {T? defaultValue}) → T?
Returns a specific custom claim by key.
inherited
getCustomClaims() Map<String, dynamic>?
Returns all custom claims from the cached token.
inherited
getTokenResult() Future<IdTokenResult?>
Returns the cached token result with claims.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
onDone(int nrOfRetry, int maxNrOfRetry) → void
Called when the stream is done.
inherited
onError(TFirestoreException error) → void
Called when a stream error occurs.
override
rebuild() → void
Forces a rebuild of the local state.
resetAndTryInitialiseStream() Future<void>
Resets and reinitialized the stream.
inherited
toString() String
A string representation of this object.
inherited
tryHandleFirebaseAuthException<T>({required FirebaseAuthException firebaseAuthException, required TLog log}) → TurboResponse<T>
Handles Firebase Authentication exceptions and converts them to TurboResponse.
inherited
tryInitialiseStream() Future<void>
Initializes the authentication state stream and data synchronization.
inherited
turboVars<V extends TAuthVars>({String? id}) → V
Returns a new instance of V with basic variables filled in.
updateDoc({Transaction? transaction, required String id, required UpdateDocDef<T> doc, TWriteable remoteUpdateRequestBuilder(T doc)?, bool doNotifyListeners = true}) Future<TurboResponse<T>>
Updates a document both locally and in Firestore.
updateLocalDoc({required String id, required UpdateDocDef<T> doc, bool doNotifyListeners = true}) → T
Updates an existing document in local state.
upsertDoc({Transaction? transaction, required String id, required UpsertDocDef<T> doc, TWriteableId remoteUpdateRequestBuilder(T doc)?, bool doNotifyListeners = true}) Future<TurboResponse<T>>
Upserts (updates or inserts) a document both locally and in Firestore.
upsertLocalDoc({required String id, required UpsertDocDef<T> doc, bool doNotifyListeners = true}) → T
Upserts (updates or inserts) a document in local state.

Operators

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