findByQueryWithConverter method

Future<FeedbackResponse<List<T>>> findByQueryWithConverter({
  1. required CollectionReferenceQuery<T> collectionReferenceQuery,
  2. required String whereDescription,
})

Finds documents based on a given searchTerm and searchField.

The searchTermType defines the type of field that is specified as searchField. You are able to search a SearchTermType.startsWith field for direct hits or for a SearchTermType.arrayContains that may contain the searchField.

This method returns data in the form of a list of T. Make sure to have specified the _toJson and _fromJson methods or else the FirestoreApi will not now how to convert the data.

If _tryAddLocalId is true then your data will also contain a local id field based on the _idFieldName specified in the constructor. Add this id field to your T and you will have easy access to the document id at any time.

If _tryAddLocalDocumentReference is true then your data will also contain a local reference field based on the _documentReferenceFieldName specified in the constructor. Add this reference field to your T and you will have easy access to the document reference at any time.

If you rather want to retrieve data in the raw form of a List<Map<String, dynamic>> consider using the findByQuery method instead.

Implementation

Future<FeedbackResponse<List<T>>> findByQueryWithConverter({
  required CollectionReferenceQuery<T> collectionReferenceQuery,
  required String whereDescription,
}) async {
  try {
    _log.info(
      message: 'Finding with converter, with custom query..',
      sensitiveData: _shouldNotSensitiveInfo
          ? null
          : SensitiveData(
              path: _collectionPath(),
              whereDescription: whereDescription,
            ),
    );
    final result =
        (await collectionReferenceQuery(findCollectionWithConverter())
                .get(_getOptions))
            .docs
            .map((e) => e.data())
            .toList();
    _logResultLength(result);
    return _responseConfig.searchSuccessResponse(
        isPlural: result.isPlural, result: result);
  } catch (error, stackTrace) {
    _log.error(
      message: 'Unable to find documents with custom query',
      sensitiveData: _shouldNotSensitiveError
          ? null
          : SensitiveData(
              path: _collectionPath(),
              whereDescription: whereDescription,
            ),
      error: error,
      stackTrace: stackTrace,
    );
    return _responseConfig.searchFailedResponse(isPlural: true);
  }
}