streamDocByIdWithConverter method
Streams and converts a single document
Returns real-time updates with automatic conversion to T
Requires _fromJson
configuration
Parameters:
id
unique identifier of the document
collectionPathOverride
override path for collection groups
Returns Stream of T?
containing:
- Converted document data
- Real-time updates
Features:
- Automatic type conversion
- Real-time updates
- Local ID field management
- Document reference handling
Example:
final stream = api.streamDocByIdWithConverter(id: 'user-123');
stream.listen((user) {
if (user != null) {
print('User name: ${user.name}');
}
});
See also: streamByDocId raw data document streaming streamAllWithConverter collection type-safe streaming
Implementation
Stream<T?> streamDocByIdWithConverter({
required String id,
String? collectionPathOverride,
}) {
assert(
_isCollectionGroup == (collectionPathOverride != null),
'Firestore does not support finding a document by id when communicating with a collection group, '
'therefore, you must specify the collectionPathOverride containing all parent collection and document ids '
'in order to make this method work.',
);
final path = collectionPathOverride ?? _collectionPath();
final docRefWithConverter = getDocRefByIdWithConverter(
id: id,
collectionPathOverride: collectionPathOverride,
);
_log.debug(
message: 'Finding doc stream with converter..',
sensitiveData: SensitiveData(
path: path,
id: id,
),
);
return docRefWithConverter.snapshots().map((e) => e.data()).handleError(
(error, stackTrace) {
_log.error(
message: 'Error streaming document with converter',
sensitiveData: SensitiveData(
path: path,
id: id,
),
error: error,
stackTrace: stackTrace,
);
throw TurboFirestoreException.fromFirestoreException(
error,
stackTrace,
path: path,
);
},
);
}