정렬 패키지는 Dart에서 복잡한 객체 목록을 정렬하기 위한 간단하고 강력한 확장 메서드를 제공합니다. 내장된 List 클래스에 직관적인 구문을 추가하여 하나 또는 여러 필드로 오름차순 및 내림차순 정렬을 지원합니다. 사용자 목록, 제품 카탈로그, API 응답과 같은 구조화된 데이터를 다루는 개발자에게 이상적이며, 반복 코드를 줄이고 가독성을 향상시킵니다. 이 패키지는 가볍고 플랫폼 독립적이며, 안드로이드, iOS, 웹, 맥OS, 윈도우, 리눅스의 Flutter 및 Dart 프로젝트에 원활하게 통합됩니다.
사용 사례
이름 또는 나이로 사용자 데이터 정렬
가격 또는 평점으로 제품 목록 정렬
API 응답 배열 정리
UI에서 동적 목록 정렬 처리
복잡한 객체 정렬 로직 간소화
주요 기능
사용하기 쉬운 확장 메서드
다중 필드 정렬을 지원합니다
오름차순 및 내림차순 정렬 처리
최소한의 보일러플레이트
모든 객체 유형과 호환됩니다
크로스 플랫폼 호환성
적합한 대상
깔끔한 정렬 구문을 찾는 개발자
자주 목록 정렬이 필요한 프로젝트
동적 데이터 표시를 갖춘 Flutter 앱
코드 가독성을 우선시하는 팀
수동 비교 논리에서 벗어나는 Dart 개발자
고려 사항
Dart 2.12 이상 필요
필드 이름에 런타임 타입 안전성이 없음
기본 정렬 패턴에 한정됨
매우 복잡한 정렬 규칙에 적합하지 않습니다
기본 필드를 초과하는 사용자 지정 비교 함수를 지원하지 않습니다
원본 README
연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.
sorted
Sort lists of complex objects with ease. Simple but powerful extension method.
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.
Sorting rules
All rules have an optional named argument invert which inverts the sorting order.
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.
Sorts items by the mapped property value using Comparable.compare which is basically a.compareTo(b). Sorts strings alphabetically, numbers ascending, etc.
SortedComparator
SortedComparator<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.