documents property

Future<List<DocumentSnapshot>> get documents

Get the documents in this collection.

Implementation

Future<List<DocumentSnapshot>> get documents async {
  final response = await service._get(collectionUri);
  int httpStatusCode = response.statusCode;

  final responseJson = json.decode(response.body) as Map<String, dynamic>;
  if (httpStatusCode == HttpStatus.ok) {
    List<dynamic> documentsJson = responseJson['documents'] as List<dynamic>;
    List<DocumentSnapshot> documents = [];
    for (var documentJson in documentsJson) {
      if (documentJson is Map<String, dynamic>) {
        final key = documentJson['name'].toString();
        documents.add(DocumentSnapshot._('$path/$key', documentJson));
      }
    }
    return documents;
  }

  // All other cases are treated as an error.
  throw CarpServiceException.fromMap(httpStatusCode, responseJson);
}