native_natural_sort 0.1.0
native_natural_sort: ^0.1.0 copied to clipboard
Locale-aware, numeric-aware natural string sorting for Flutter using each platform's native collation engine.
native_natural_sort #
Locale-aware, numeric-aware natural string sorting for Flutter using each platform's native collation engine.
Features #
- ✅ Cross-platform: Android, iOS, macOS, Linux, Windows
- ✅ Locale-aware sorting via each platform's native collation engine
- ✅ Numeric-aware natural sort (e.g.
file2<file10) - ✅ Sort-time locale and direction overrides
- ✅ Dual Windows backends: Pigeon (
CompareStringEx) or FFI (ICU) - ✅ Direct FFI access via
IcuCollationfor advanced use cases
Getting started #
Add dependency with flutter pub add command #
flutter pub add native_natural_sort
Or add below line to pubspec.yaml #
dependencies:
...
native_natural_sort: any # or specific version
Then run flutter pub get.
Usage #
import 'package:native_natural_sort/native_natural_sort.dart';
final sort = NativeSort();
await sort.config(SortOptions());
final sorted = await sort.sort([
SortItem(id: 'a', value: 'file10.txt'),
SortItem(id: 'b', value: 'file2.txt'),
SortItem(id: 'c', value: 'file1.txt'),
]);
// sorted: [c, b, a] (file1 < file2 < file10)
Platform-specific options #
await sort.init(SortOptions(
android: SortOptionsAndroid(
locale: Locale('zh'),
direction: SortDirection.descending,
),
windows: SortOptionsWindows(
locale: Locale('en'),
sort: WindowsSort.ffi(), // or WindowsSort.pigeon() (default)
),
));
Sort-time overrides #
final sorted = await sort.sort(
items,
locale: Locale('fr'),
direction: SortDirection.descending,
);
Windows backend selection #
| Backend | Technology | Notes |
|---|---|---|
WindowsSort.pigeon() |
CompareStringEx (Win32) |
Default |
WindowsSort.ffi() |
OS-bundled ICU DLL | Requires Windows 10 1703+ |
Direct FFI access #
import 'package:native_natural_sort/native_natural_sort.dart';
final collation = IcuCollation(engine);
final sorted = collation.sort(items: [...], idOf: ..., valueOf: ...);
For more examples, see the integration tests.
Architecture #
NativeSortService (unified Dart API)
├── Android → Pigeon → android.icu.text.Collator
├── iOS → Pigeon → localizedStandardCompare
├── macOS → Pigeon → localizedStandardCompare
├── Linux → Dart FFI → system libicui18n
└── Windows → Pigeon (CompareStringEx) or FFI (ICU)
Development #
# Regenerate platform channel code
make gen
# Run analysis
make analyze
# Run tests
make test
Donate #
License #
MIT License
Copyright (c) 2026 Fries_I23
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.