delete method

Future<void> delete()

Deletes the document referred to by this DocumentReference.

Implementation

Future<void> delete() async {
  // if we don't have the document ID, get it first.
  if (id == null) _id = (await get())?.id;
  if (_id == null) return; // early out if this document does not exist

  http.Response response = await http
      .delete(Uri.parse(Uri.encodeFull(documentUri)), headers: headers);

  int httpStatusCode = response.statusCode;
  if (httpStatusCode == HttpStatus.ok) {
    return;
  } else {
    final Map<String, dynamic> responseJson =
        json.decode(response.body) as Map<String, dynamic>;
    throw CarpServiceException(
      httpStatus: HTTPStatus(httpStatusCode, response.reasonPhrase),
      message: responseJson["message"].toString(),
      path: responseJson["path"].toString(),
    );
  }
}