streamAllWithConverter method

Stream<List<T>> streamAllWithConverter()

Streams and converts all documents from a collection with error handling

Returns real-time updates with automatic conversion to T Requires _fromJson configuration Errors are caught and transformed to TurboFirestoreException

Returns Stream of List<T> containing:

  • Converted document data
  • Real-time updates

Example:

final stream = api.streamAllWithConverter();
stream.listen(
  (users) {
    for (var user in users) {
      print('User name: ${user.name}');
    }
  },
  onError: (error) {
    if (error is TurboFirestoreUnavailableException) {
      print('Service unavailable: ${error.message}');
    }
  }
);

See also: streamAll raw data streaming streamByQueryWithConverter filtered type-safe streaming

Implementation

Stream<List<T>> streamAllWithConverter() {
  final path = _collectionPath();
  _log.debug(
    message: 'Finding stream with converter..',
    sensitiveData: SensitiveData(
      path: path,
    ),
  );
  return listCollectionReferenceWithConverter()
      .snapshots()
      .map(
        (event) => event.docs.map((e) => e.data()).toList(),
      )
      .handleError(
    (error, stackTrace) {
      _log.error(
        message: 'Error streaming collection with converter',
        sensitiveData: SensitiveData(
          path: path,
        ),
        error: error,
        stackTrace: stackTrace,
      );
      throw TurboFirestoreException.fromFirestoreException(
        error,
        stackTrace,
        path: path,
      );
    },
  );
}