paginate method

Future<List<ISQLiteItem>> paginate(
  1. ISQLiteItem item,
  2. int limit,
  3. int offset
)

Retrieves a paginated list of items from the SQLite database.

This method fetches a subset of records from the specified table, based on the provided limit (maximum number of rows) and offset (the starting row index).

  • item: The table item (implements ISQLiteItem) from which to fetch data.
  • limit: The maximum number of rows to return in the result set.
  • offset: The starting point in the result set to begin returning records.

Returns a Future<List<ISQLiteItem>> containing a paginated list of records.

Implementation

Future<List<ISQLiteItem>> paginate(
    ISQLiteItem item, int limit, int offset) async {
  // Opens the SQLite database.
  var db = await getOpenDatabase();

  // Queries the table with a specified limit and offset.
  var maps =
      await db.query(item.getTableName(), limit: limit, offset: offset);

  // Maps the database rows to the item model and returns the result as a list.
  return maps.map((map) => item.fromMap(map)).toList();
}