orderBy method

void orderBy(
  1. String field, {
  2. bool ascending = true,
})

You can call this method to sort query results by a specified field. You are advised to call this method after all the other methods.

When using this method to sort fields, you are advised to create indexes for the sorted fields. Otherwise, when the number of data records of the object type reaches a certain value, the query may time out or fail due to low query efficiency, affecting user experience.

Implementation

void orderBy(String field, {bool ascending = true}) {
  if (field.isEmpty) {
    throw FormatException('field cannot be an empty string.', field);
  }
  _queryElements.add(
    <String, dynamic>{
      _QueryConstants.FIELD: field,
      _QueryConstants.OPERATION: ascending
          ? _QueryConstants.ORDER_BY_ASC
          : _QueryConstants.ORDER_BY_DESC,
    },
  );
}