native_natural_sort
Locale-aware, numeric-aware natural string sorting for Flutter using each platform's native collation engine.
Features
xCross-platform: Android, iOS, macOS, Linux, WindowsxLocale-aware sorting via each platform's native collation enginexNumeric-aware natural sort (e.g.file2<file10)xSort-time locale and direction overridesxDual Windows backends: Pigeon (CompareStringEx) or FFI (ICU)xDirect FFI access viaIcuCollationfor 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.config(SortOptions(
android: SortOptionsAndroid(
locale: Locale('zh'),
direction: SortDirection.descending,
),
windows: SortOptionsWindows(
locale: Locale('en'),
sort: WindowsSort.ffi(), // or WindowsSort.pigeon()
),
));
Sort-time overrides
final sorted = await sort.sort(
items,
locale: Locale('fr'),
direction: SortDirection.descending,
);
Windows backend selection
| Backend | Technology | Notes |
|---|---|---|
WindowsSort.ffi() |
OS-bundled ICU DLL | Default |
WindowsSort.pigeon() |
CompareStringEx (Win32) |
Direct FFI access
import 'package:native_natural_sort/native_natural_sort.dart';
final loader = MyCollationLibraryLoader(); // see Linux/Windows FFI loaders
await loader.init();
final collator = loader.collator('en');
final sorted = collator.sort(
items: ['file10.txt', 'file2.txt', 'file1.txt'],
idOf: (s) => s,
valueOf: (s) => s,
);
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
This project is licensed under the Apache License, Version 2.0. See LICENSE for the full license text.
Copyright 2026 Fries_I23
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.