パッケージ、リポジトリ、アプリカテゴリを検索

パッケージ詳細v2.1.0

sorted

複雑なオブジェクトのリストを簡単に並べ替えます。シンプルだが強力な拡張メソッド。

AndroidiOSWebmacOSWindowsLinux
30日間ダウンロード
393
いいね数
31
Pub ポイント
140

パッケージをインストール

flutter pub add sorted

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

ソートパッケージは、Dartで複雑なオブジェクトのリストをソートするためのシンプルかつ強力な拡張メソッドを提供します。ビルトインのListクラスに、1つまたは複数のフィールドで昇順・降順にソートできる直感的な構文を追加しています。ユーザー一覧や製品カタログ、API応答などの構造化データを扱う開発者にとって理想的であり、ボイラープレートコードを減らし、読みやすさを向上させます。このパッケージは軽量で、プラットフォームに依存せず、Android、iOS、Web、macOS、Windows、Linux上のFlutterおよびDartプロジェクトにスムーズに統合できます。

用途

  • 名前または年齢でユーザー情報を並べ替えます
  • 価格または評価で製品リストを並べ替えます
  • API応答配列の整理
  • UIにおける動的リストの並べ替え処理
  • 複雑なオブジェクトソートロジックの簡素化

主な機能

  • 使いやすい拡張メソッド
  • 複数フィールドの並べ替えをサポートしています
  • 昇順および降順の処理
  • 最小限のボイラープレート
  • 任意のオブジェクト型と連携可能
  • クロスプラットフォーム互換性

適している対象

  • 明確なソート構文を求める開発者
  • 頻繁にリストを並べ替えるプロジェクト
  • 動的なデータ表示を備えた Flutter アプリ
  • コードの可読性を最優先とするチーム
  • Dart開発者が手動の比較ロジックを回避する

注意事項

  • Dart 2.12+ を必要とします
  • フィールド名の実行時型の安全性がない
  • 基本的な並べ替えパターンに限定される
  • 非常に複雑な並べ替えルールには適していません
  • 基本フィールドを超えるカスタム比較関数はサポートされていません

元の README

関連するソースリポジトリの README 原文のスナップショットです。最新の内容はリポジトリをご覧ください。

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.

カテゴリー

依存関係

依存関係一覧 1 件

ソースリポジトリ

このパッケージを使用しているプロジェクト

データはまだありません。