limit method Null safety

void limit(
  1. int count,
  2. {int? offset}
)

You can invoke this method to add query conditions to specify the number of data records in the returned query result set.

  • If you do not set offset, the first count objects are obtained by default. If the number of objects in the query result set is less than count, all objects are returned.
  • If offset is set, the first count objects starting from the offset position are returned. If the number of objects starting from the offset position is less than the count value, all object data starting from the offset position is returned.

Implementation

void limit(int count, {int? offset}) {
  if (count < 1) {
    throw FormatException('count cannot be less than 1.', count);
  }
  if (offset != null && offset < 1) {
    throw FormatException('offset should be greater than 0.', offset);
  }
  _queryElements.add(
    <String, dynamic>{
      _QueryConstants.OPERATION: _QueryConstants.LIMIT,
      _QueryConstants.VALUE: count,
      _QueryConstants.OFFSET: offset,
    },
  );
}