where method

PaginatedModel<T> where(
  1. bool test(
    1. T item
    )
)

Filters items using a custom test function

Example:

final result = response.where((item) =>
  item.price > 100 && item.stock > 0
);

test A function that returns true for items to keep

Implementation

PaginatedModel<T> where(bool Function(T item) test) {
  final filteredItems = items?.where(test).toList();
  return PaginatedModel<T>(
    items: filteredItems,
    pagination: pagination?.copyWith(
      totalItems: filteredItems?.length ?? 0,
      itemCount: filteredItems?.length ?? 0,
      itemsPerPage: pagination?.itemsPerPage,
      totalPages: pagination?.totalPages,
      currentPage: pagination?.currentPage,
    ),
  );
}