Search packages, repositories and app categories

Package detailsv2.1.0

sorted

Sort lists of complex objects with ease. Simple but powerful extension method.

AndroidiOSWebmacOSWindowsLinux
30-day downloads
454
Likes
31
Pub points
140

Install package

flutter pub add sorted

Package Overview

Package selection guidance compiled from public package information, community data, and project usage.

The sorted package provides a simple and powerful extension method for sorting lists of complex objects in Dart. It enhances the built-in List class with intuitive syntax to sort by one or multiple fields, supporting both ascending and descending order. Ideal for developers working with structured data like user lists, product catalogs, or API responses, it reduces boilerplate code and improves readability. The package is lightweight, platform-agnostic, and integrates seamlessly into Flutter and Dart projects across Android, iOS, Web, macOS, Windows, and Linux.

Use cases

  • Sorting user data by name or age
  • Ordering product lists by price or rating
  • Organizing API response arrays
  • Handling dynamic list sorting in UIs
  • Simplifying complex object sorting logic

Key features

  • Easy-to-use extension method
  • Supports multi-field sorting
  • Handles ascending and descending order
  • Minimal boilerplate
  • Works with any object type
  • Cross-platform compatibility

Suitable for

  • Developers seeking clean sorting syntax
  • Projects with frequent list sorting
  • Flutter apps with dynamic data display
  • Teams prioritizing code readability
  • Dart developers avoiding manual comparator logic

Considerations

  • Requires Dart 2.12+
  • No runtime type safety for field names
  • Limited to basic sorting patterns
  • Not suitable for highly complex sorting rules
  • Does not support custom comparison functions beyond basic fields

Original README

Original README snapshot from the linked source repository. Visit the repository for the latest content.

sorted

Package on pub.dev Test suite

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,
    )
]);

Usage

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.

Sorting rules

All rules have an optional named argument invert which inverts the sorting order.

SortedOrdered
SortedOrdered<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.

SortedGroupOrdered
SortedOrdered<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.

SortedComparable
SortedComparable<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.

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.

Categories

Dependencies

Dependency list 1 items

Source repository

Projects using this package

No data available yet.