createFolder method

  1. @override
Future<RequestResponse<bool?>> createFolder({
  1. required String folderName,
  2. String? parentFolder = 'Home',
})
override

Returns bool within RequestResponse after creating folder.

If unsuccessful, the false is returned within RequestResponse.

Optionally, specify the parentFolder which defaults to 'Home'.

folderName must not contain a forward-slash, otherwise an error is returned within RequestResponse.

Implementation

@override
Future<RequestResponse<bool?>> createFolder(
    {required String folderName, String? parentFolder = 'Home'}) async {
  if (folderName.contains('/')) {
    return RequestResponse.fail(handleError(
        'invalid_foldername_forward_slash',
        ErrorDetail(info: Information(httpCode: 412))));
  }

  final response = await Request.initiateRequest(
      url: config.hostUrl,
      method: HttpMethod.POST,
      contentType: ContentTypeLiterals.APPLICATION_X_WWW_FORM_URLENCODED,
      data: <String, dynamic>{
        'cmd': 'frappe.core.doctype.file.file.create_new_folder',
        'file_name': folderName,
        'folder': parentFolder
      });

  return response.isSuccess
      ? RequestResponse.success(true, rawResponse: response.rawResponse)
      : RequestResponse.fail(handleError('create_folder', response.error));
}