sortBy method
Sorts items using a one-time comparator without changing the active order.
This is useful for temporary sorting that doesn't persist.
Example:
cubit.sortBy((a, b) => a.price.compareTo(b.price));
Implementation
void sortBy(ItemComparator<T> comparator) {
final currentState = state;
if (currentState is! SmartPaginationLoaded<T>) return;
final sorted = List<T>.from(currentState.items)..sort(comparator);
final sortedAll = List<T>.from(currentState.allItems)..sort(comparator);
emit(
currentState.copyWith(
items: sorted,
allItems: sortedAll,
lastUpdate: DateTime.now(),
),
);
}