rename method
Rename this collection.
Implementation
Future<void> rename(String newName) async {
// PUT the new name of this collection to the CARP web service
final response = await httpr.put(Uri.encodeFull(collectionUriByID),
headers: headers, body: '{"name":"$newName"}');
int httpStatusCode = response.statusCode;
Map<String, dynamic> responseJson =
json.decode(response.body) as Map<String, dynamic>;
if (httpStatusCode == HttpStatus.ok) {
int start = _path.length - _path.split('/').last.length;
_path = _path.replaceRange(start, _path.length,
newName); // renaming path, i.e. the last part of the path
return;
}
// All other cases are treated as an error.
throw CarpServiceException(
httpStatus: HTTPStatus(httpStatusCode, response.reasonPhrase),
message: responseJson['message'].toString(),
path: responseJson["path"].toString(),
);
}