SortOrder<T> class
Configuration for sorting paginated items.
Allows you to define how items should be sorted by providing either:
- A custom
comparatorfunction for complete control - A
fieldSelectorwith a direction for simple field-based sorting
Example usage:
// Using comparator
final byPrice = SortOrder<Product>(
id: 'price',
label: 'Price',
comparator: (a, b) => a.price.compareTo(b.price),
);
// Using field selector
final byName = SortOrder<Product>.byField(
id: 'name',
label: 'Name',
fieldSelector: (product) => product.name,
direction: SortDirection.ascending,
);
// Descending order
final byNewest = SortOrder<Product>.byField(
id: 'createdAt',
label: 'Newest First',
fieldSelector: (product) => product.createdAt,
direction: SortDirection.descending,
);
Constructors
-
SortOrder({required String id, required String label, required ItemComparator<
T> comparator}) -
Creates a sort order with a custom comparator.
const
- SortOrder.byField({required String id, required String label, required Comparable fieldSelector(T item), SortDirection direction = SortDirection.ascending})
- Creates a sort order based on a field selector.
Properties
- direction → SortDirection
-
Returns the sort direction.
no setter
- hashCode → int
-
The hash code for this object.
no setteroverride
- id → String
-
Unique identifier for this sort order.
final
- label → String
-
Human-readable label for display in UI.
final
-
reversed
→ SortOrder<
T> -
Creates a reversed version of this sort order.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
compare(
T a, T b) → int - Compares two items according to this sort order.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
sort(
List< T> items) → List<T> - Sorts a list of items according to this sort order.
-
toString(
) → String -
A string representation of this object.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
override