FirestoreDocRepository<T extends JsonModel> class

A small, opinionated single-document repository that:

  1. Reacts to auth changes (attaches/detaches via UID),
  2. Primes state from the local cache for instant UI,
  3. Streams live updates (or can be one-shot),
  4. Exposes simple write/update/patch/delete Commands.

Auth-gated usage (per-user documents):

final repo = FirestoreDocRepository<UserProfile>(
  firestore: FirebaseFirestore.instance,
  fromJson: (m) => UserProfile.fromJson(m),
  docRefBuilder: (fs, uid) => fs.doc('users/$uid'),
  authUid: myAuthUidListenable, // ValueListenable<String?>
  subscribe: true,
);

Public usage (no auth required):

final repo = FirestoreDocRepository<AppConfig>(
  firestore: FirebaseFirestore.instance,
  fromJson: (m) => AppConfig.fromJson(m),
  docRefBuilder: (fs, uid) => fs.doc('static/config'),
  // omit authUid — queries Firestore immediately
  subscribe: true,
);
Inheritance

Constructors

FirestoreDocRepository({required T fromJson(Map<String, dynamic>), required DocumentReference<Map<String, dynamic>> docRefBuilder(FirebaseFirestore fs, String? uid), FirebaseFirestore? firestore, AuthUidListenable? authUid, bool subscribe = true})

Properties

delete → Command<void, void>
Deletes the document.
latefinal
hashCode int
The hash code for this object.
no setterinherited
hasInitialized ValueNotifier<bool>
Flips to true after the first successful load (from cache or server) and never reverts. Use this to distinguish "never loaded" from "loaded but value is null (document doesn't exist)".
final
hasListeners bool
Whether any listeners are currently registered.
no setterinherited
isLoading ValueNotifier<bool>
Whether the repository is currently fetching data from Firestore.
final
patch → Command<Map<String, dynamic>, void>
Partially updates specific fields on the document.
latefinal
ready Future<T?>
A Future that completes with the first loaded value (which may be null if the document does not exist). Useful for one-time await in services that need the data before proceeding.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
update → Command<T, void>
Replaces all fields on the existing document with model.
latefinal
value ↔ T?
The current value stored in this notifier.
getter/setter pairinherited
write → Command<T, void>
Creates or merges a document with the full model.
latefinal

Methods

addListener(VoidCallback listener) → void
Register a closure to be called when the object changes.
inherited
dispose() → void
Discards any resources used by the object. After this is called, the object is not in a usable state and should be discarded (calls to addListener will throw after the object is disposed).
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
notifyListeners() → void
Call all the registered listeners.
inherited
removeListener(VoidCallback listener) → void
Remove a previously registered closure from the list of closures that are notified when the object changes.
inherited
toString() String
A string representation of this object.
inherited

Operators

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