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 TFirestoreException

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: TSensitiveData(
      path: path,
    ),
  );
  return listCollectionReferenceWithConverter()
      .snapshots()
      .map(
        (event) => event.docs.map((e) => e.data()).toList(),
      )
      .handleError(
        (Object error, StackTrace stackTrace) {
          final exception = _createException(
            error: error,
            stackTrace: stackTrace,
            path: path,
            operationType: TOperationType.stream,
          );
          _log.error(
            message: 'Error streaming collection with converter',
            sensitiveData: TSensitiveData(
              path: path,
              operationType: TOperationType.stream,
              fullPath: path,
            ),
            error: error,
            stackTrace: stackTrace,
          );
          throw exception;
        },
      );
}