sorted
복잡한 객체 목록을 쉽게 정렬하세요. 간단하지만 강력한 확장 메서드입니다.
복잡한 객체 목록을 쉽게 정렬하세요. 간단하지만 강력한 확장 메서드입니다.
^1.15.0^2.1.1^1.5.3^5.0.15^1.17.11아래는 영문 원문 스냅샷입니다. 최신 내용은 GitHub에서 확인하세요.
Sort lists of complex objects with ease. Simple but powerful extension method.
auctions.sorted([
SortedOrdered<Auction, AuctionStatus>(
(action) => auction.buyerContext.status,
[AuctionStatus.live, AuctionStatus.won, AuctionStatus.lost],
),
SortedComparable<Auction, DateTime>((auction) => auction.endedAt),
SortedComparable<Auction, DateTime>(
(auction) => auction.endedAt,
invert: true,
)
]);
Add the package to your pubspec.yaml:
dependencies:
sorted: <newest version>
Import the package:
import 'package:sorted/sorted.dart';
Call sorted extension method on any list and pass sorting rules of your choice. Order matters, so if first rule considers two items equal, next one will decide and so on.
All rules have an optional named argument invert which inverts the sorting order.
SortedOrderedSortedOrdered<Auction, AuctionStatus>(
(auction) => auction.buyerContext.status,
[AuctionStatus.live, AuctionStatus.won, AuctionStatus.lost],
)
Sorts items by the mapped property value in an order passed as a second argument. In this example, live auctions will be first, then won, and then lost.
SortedGroupOrderedSortedOrdered<Road, RoadType>(
(road) => road.type,
[
[RoadType.nationalHighway, RoadType.stateHighway],
[RoadType.district],
[RoadType.dirt],
],
)
Sorts items by the mapped property value in the order of order groups, but all values withing a certain group are considered equal.
SortedComparableSortedComparable<User, String>((user) => user.lastName)
Sorts items by the mapped property value using Comparable.compare which is basically a.compareTo(b). Sorts strings alphabetically, numbers ascending, etc.
SortedComparatorSortedComparator<Auction, String>(
(auction) => auction.buyerContext.status,
(a, b) => /* your custom compare function */,
)
Sorts items by the mapped property value using a custom comparator provided as a second argument.