rename method
Renames the document referred to by this DocumentReference.
Implementation
@Deprecated('Documents cannot be renamed in CANS.')
Future<DocumentSnapshot> rename(String name) async {
assert(name.length > 0, 'Document path names cannot be empty.');
assert(RegExp(r'^[a-zA-Z0-9_-]+$').hasMatch(name),
'Document name can only contain alphanumeric, hyphen (-), and underscore (_) characters.');
// if we don't have the document ID, get it first.
if (id == null) _id = (await this.get())?.id;
if (_id == null) // early out if this document does not exist
throw CarpServiceException(message: 'No valid document id found.');
Map<String, dynamic> payload = {'name': name};
http.Response response = await httpr.put(
Uri.encodeFull(documentUri),
headers: headers,
body: json.encode(payload),
);
int httpStatusCode = response.statusCode;
Map<String, dynamic> responseJson = json.decode(response.body);
if (httpStatusCode == HttpStatus.ok)
return DocumentSnapshot._(path, responseJson);
throw CarpServiceException(
httpStatus: HTTPStatus(httpStatusCode, response.reasonPhrase),
message: responseJson["message"],
path: responseJson["path"],
);
}