getValue method

  1. @override
Future<RequestResponse<Map<String, dynamic>?>> getValue(
  1. String doctype,
  2. String docName,
  3. String docField
)
override

Returns a Map of docfield and its value of a specific doctype and docName from the backend. For instance:

{
"email": "abc@example.com"
}

Returns a failure in case doctype, docName or docField don't exist.

Implementation

@override
Future<RequestResponse<Map<String, dynamic>?>> getValue(
    String doctype, String docName, String docField) async {
  EmptyDoctypeError.verify(doctype);
  EmptyDocNameError.verify(docName);
  EmptyDocFieldError.verify(docField);

  final params = GetValueParams(doctype, docName, docField);
  params.cmd = 'frappe.client.get_value';

  final response = await Request.initiateRequest(
      url: config.hostUrl,
      method: HttpMethod.GET,
      contentType: ContentTypeLiterals.QUERY_STRING,
      queryParams: params.toJson());
  if (response.isSuccess) {
    if (response.data?.message != null) {
      return RequestResponse.success(response.data!.message,
          rawResponse: response.rawResponse);
    } else {
      response.isSuccess = false;
      return RequestResponse.fail(handleError(
          'get_value',
          ErrorDetail(
              info: Information(
                  data: response.data,
                  httpCode: response.httpCode,
                  rawResponse: response.rawResponse))));
    }
  } else {
    return RequestResponse.fail(handleError('get_value', response.error));
  }
}