getList<T extends FrappeDocument> method

  1. @override
Future<RequestResponse<List<T?>?>> getList<T extends FrappeDocument>(
  1. T obj, {
  2. List<String>? fields,
  3. dynamic filters,
  4. String? orderBy = 'modified desc',
  5. int? limitPageStart = 0,
  6. int? limitPageLength = 99,
  7. String? parent,
  8. Map<String, List<String>>? tableFields,
  9. List<String>? withLinkFields,
})
override

Returns list of documents T of a doctype specified by obj.

By default, only the name field of the documents is fetched.

If the fields property is specified as ["*"], all the fields of a document will be fetched.

By default, child tables are not included and have to be specified under tableFields.

filters must comply with DBFilter specifications. Throws InvalidFrappeFilter otherwise.

By default, the list will return 99 items specified by limitPageLength.

By default, the list will start from the index 0 in the DB specified by limitPageStart.

The list can be ordered in the following format specified by orderBy :

  • {{field_name}} asc|desc
  • By default, the list is ordered by modification timestamp (modified)

Implementation

@override
Future<RequestResponse<List<T?>?>> getList<T extends FrappeDocument>(T obj,
    {List<String>? fields,
    dynamic filters,
    String? orderBy = 'modified desc',
    int? limitPageStart = 0,
    int? limitPageLength = 99,
    String? parent,
    Map<String, List<String>>? tableFields,
    List<String>? withLinkFields}) async {
  await getFrappe()
      .checkAppInstalled(features: ['getList'], throwError: false);

  orderBy ??= 'modified desc';
  limitPageStart ??= 0;
  limitPageLength ??= 0;
  fields ??= <String>['name'];

  EmptyDoctypeError.verify(obj.doctype);

  if (filters != null) {
    if (!DBFilter.isDBFilter(filters)) throw InvalidFrappeFilter();
  }

  final params = GetListParams(obj.doctype,
      fields: fields.join(','),
      filters: filters != null ? jsonEncode(filters) : null,
      orderBy: orderBy,
      limitPageLength: limitPageLength,
      limitPageStart: limitPageStart,
      parent: parent,
      tableFieldsFrappe: tableFields != null ? jsonEncode(tableFields) : null,
      withLinkFieldsFrappe:
          withLinkFields != null ? jsonEncode(withLinkFields) : null);

  // Whether custom features are used
  final isUsingCustomFeatures = tableFields != null || withLinkFields != null;

  if (getFrappe().getAppsVersion('renovation_core') == null &&
      isUsingCustomFeatures) {
    // Will throw an error
    await getFrappe()
        .checkAppInstalled(features: ['tableFields', 'withLinkFields']);
  }

  params.cmd = getFrappe().getAppsVersion('renovation_core') != null
      ? 'renovation_core.db.query.get_list_with_child'
      : 'frappe.client.get_list';

  final response = await Request.initiateRequest(
      url: config.hostUrl,
      method: HttpMethod.POST,
      contentType: ContentTypeLiterals.QUERY_STRING,
      queryParams: params.toJson());
  if (response.isSuccess) {
    // Convert the JSON => T
    final responseObj = obj.deserializeList<T>(response.data!.message)!;
    for (var i = 0; i < responseObj.length; i++) {
      responseObj[i].rawResponse = response.data!.message[i];
    }

    return RequestResponse.success(responseObj,
        rawResponse: response.rawResponse);
  } else {
    return RequestResponse.fail(handleError('get_list', response.error));
  }
}